Skip to content

Commit 838bab7

Browse files
committed
1 parent 6487677 commit 838bab7

File tree

5 files changed

+16
-44
lines changed

5 files changed

+16
-44
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: classInt
22
Version: 0.4-11
3-
Date: 2024-11-26
3+
Date: 2025-01-06
44
Title: Choose Univariate Class Intervals
55
Authors@R: c(
66
person("Roger", "Bivand", role=c("aut", "cre"), email="[email protected]", comment=c(ORCID="0000-0003-2392-6140")),

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Version 0.4-11
22

3-
- #49 permit use of `"quantile"` `style` `probs=` argument; should really use `n=`, as `probs` is set internally to `seq(0, 1, 1/n)`. For other vectors, the use of `"fixed"` `style` is preferable.
3+
- #49 explicitly forbid use of `"quantile"` style `probs=` argument; should really use `n=`, as `probs` is set internally to `seq(0, 1, 1/n)`. Similarly, forbid `centers=` argument in `"kmeans"` and `"bclust"` styles as it is set internally to `n`.
44

55
## Version 0.4-10
66

R/classInt.R

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -191,40 +191,19 @@ classIntervals <- function(var, n, style="quantile", rtimes=3, ..., intervalClos
191191
brks <- c(pretty(x=var, n=n, ...))
192192
} else if (style =="quantile") {
193193
# stats
194-
dots <- list(...)
195194
probs <- seq(0, 1, 1/n)
195+
dots <- list(...)
196196
if (!is.null(dots$probs)) {
197-
if (n_missing) {
198-
probs <- dots$probs
199-
} else {
200-
if (length(dots$probs)-1 != n) {
201-
stop("both n and probs given, but length(probs)-1 != ", n)
202-
} else probs <- dots$probs
203-
}
204-
r_probs <- range(probs)
205-
if (r_probs[1] < 0 || r_probs[2] > 1)
206-
stop("given probs range exceeds the unit interval: [",
207-
paste(r_probs, collapse=", "), "]")
208-
if (r_probs[1] != 0 || r_probs[2] != 1) {
209-
warning("given probs range does not span the unit interval: [",
210-
paste(r_probs, collapse=", "), "]")
211-
}
212-
if (length(unique(round(diff(probs), digits=14))) != 1L)
213-
warning("given probs do not have equal steps")
197+
stop("probs is set internally to seq(0, 1, 1/n) for style quantile\nit must not be passed in ...")
214198
}
215-
na.rm <- FALSE
216-
if (!is.null(dots$na.rm)) na.rm <- dots$na.rm
217-
names <- FALSE
218-
if (!is.null(dots$names)) names <- dots$names
219-
type <- 7
220-
if (!is.null(dots$type)) type <- dots$type
221-
digits <- 7
222-
if (!is.null(dots$digits)) digits <- dots$digits
223-
brks <- c(quantile(x=var, probs=probs, na.rm=na.rm, names=names,
224-
type=type, digits=digits))
199+
brks <- c(quantile(x=var, probs=probs, ...))
225200
names(brks) <- NULL
226201
} else if (style =="kmeans") {
227202
# stats
203+
dots <- list(...)
204+
if (!is.null(dots$centers)) {
205+
stop("centers is set internally to n for style kmeans\nit must not be passed in ...")
206+
}
228207
pars <- try(kmeans(x=var, centers=n, ...))
229208
if (inherits(pars, "try-error")) {
230209
warning("jittering in kmeans")
@@ -252,6 +231,10 @@ classIntervals <- function(var, n, style="quantile", rtimes=3, ..., intervalClos
252231
brks <- .rbrks(rbrks)
253232
} else if (style =="bclust") {
254233
# e1071, class
234+
dots <- list(...)
235+
if (!is.null(dots$centers)) {
236+
stop("centers is set internally to n for style bclust\nit must not be passed in ...")
237+
}
255238
pars <- try(bclust(x=var, centers=n, ...))
256239
if (inherits(pars, "try-error")) {
257240
warning("jittering in bclust")

inst/tinytest/test_quantile_probs.R

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@ library(classInt)
22
# issue #1
33
set.seed(101)
44
data_censored <- c(rep(0,10), rnorm(100, mean=20,sd=1),rep(26,10))
5-
expect_silent(classInt::classIntervals(data_censored, style = "quantile",
6-
probs = seq(0, 1, 0.25)))
7-
expect_error(classInt::classIntervals(data_censored, style = "quantile",
8-
n = 5, probs = seq(0, 1, 0.25)))
9-
expect_silent(classInt::classIntervals(data_censored, style = "quantile",
10-
n = 4, probs = seq(0, 1, 0.25)))
115
expect_error(classInt::classIntervals(data_censored, style = "quantile",
12-
probs = seq(-0.25, 1.25, 0.25)))
13-
expect_warning(classInt::classIntervals(data_censored, style = "quantile",
14-
probs = seq(0.25, 0.75, 0.25)))
15-
expect_error(classInt::classIntervals(data_censored, style = "quantile",
16-
probs = seq(0, 1, 0.25)-0.25))
17-
expect_warning(classInt::classIntervals(data_censored, style = "quantile",
18-
probs = c(0, 0.15804, 0.36603, 0.63975, 1))) # log sequence (bigsnpr::seq_log(1, 3, 5)-1)/2
6+
probs = seq(0, 1, 0.25)))
7+

man/classIntervals.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ classIntervals2shingle(x)
5353

5454
The "pretty" style chooses a number of breaks not necessarily equal to n using \code{pretty}, but likely to be legible; arguments to \code{pretty} may be passed through \code{\dots}.
5555

56-
The "quantile" style provides quantile breaks; arguments to \code{quantile} may be passed through \code{\dots}. Rather than giving \code{probs}, use the \code{n} argument as by default \code{probs = seq(0, 1, 1/n)}. If \code{probs} is given, it should span the unit interval [0, 1]. If given \code{probs} values do not have equal steps, consider using \code{style = "fixed"} and giving \code{"fixedBreaks"} directly.
56+
The "quantile" style provides quantile breaks; arguments to \code{quantile} may be passed through \code{\dots}. \code{probs} is never permitted, as it is set using the \code{n} argument to \code{probs = seq(0, 1, 1/n)}.
5757

5858
The "kmeans" style uses \code{kmeans} to generate the breaks; it may be anchored using \code{set.seed}; the \code{pars} attribute returns the kmeans object generated; if \code{kmeans} fails, a jittered input vector containing \code{rtimes} replications of \code{var} is tried --- with few unique values in \code{var}, this can prove necessary; arguments to \code{kmeans} may be passed through \code{\dots}.
5959

0 commit comments

Comments
 (0)