Skip to content

Commit 936157b

Browse files
committed
addressing #49
1 parent 240703c commit 936157b

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: classInt
2-
Version: 0.4-10
3-
Date: 2023-08-24
2+
Version: 0.4-11
3+
Date: 2024-11-26
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")),

R/classInt.R

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ classIntervals <- function(var, n, style="quantile", rtimes=3, ..., intervalClos
107107
# Fix 22: Diego Hernangómez
108108
needn <- !(style %in% c("dpih", "headtails", "box"))
109109

110-
if (missing(n)) n <- nclass.Sturges(var)
110+
n_missing <- FALSE
111+
if (missing(n)) {
112+
n <- nclass.Sturges(var)
113+
n_missing <- TRUE
114+
}
111115
if (n < 2 & needn) stop("n less than 2")
112116
n <- as.integer(n)
113117
pars <- NULL
@@ -187,7 +191,27 @@ classIntervals <- function(var, n, style="quantile", rtimes=3, ..., intervalClos
187191
brks <- c(pretty(x=var, n=n, ...))
188192
} else if (style =="quantile") {
189193
# stats
190-
brks <- c(quantile(x=var, probs=seq(0,1,1/n), ...))
194+
dots <- list(...)
195+
probs <- seq(0,1,1/n)
196+
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+
}
205+
na.rm <- FALSE
206+
if (!is.null(dots$na.rm)) na.rm <- dots$na.rm
207+
names <- FALSE
208+
if (!is.null(dots$names)) names <- dots$names
209+
type <- 7
210+
if (!is.null(dots$type)) type <- dots$type
211+
digits <- 7
212+
if (!is.null(dots$digits)) digits <- dots$digits
213+
brks <- c(quantile(x=var, probs=probs, na.rm=na.rm, names=names,
214+
type=type, digits=digits))
191215
names(brks) <- NULL
192216
} else if (style =="kmeans") {
193217
# stats
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
library(classInt)
2+
# issue #1
3+
set.seed(101)
4+
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)))
11+

man/classIntervals.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Dent, B. D., 1999, Cartography: thematic map design. McGraw-Hill, Boston, 417 pp
9696

9797
Slocum TA, McMaster RB, Kessler FC, Howard HH 2005 Thematic Cartography and Geographic Visualization, Prentice Hall, Upper Saddle River NJ.;
9898

99-
Fisher, W. D. 1958 "On grouping for maximum homogeneity", Journal of the American Statistical Association, 53, pp. 789--798 (\url{http://lib.stat.cmu.edu/cmlib/src/cluster/fish.f})
99+
Fisher, W. D. 1958 "On grouping for maximum homogeneity", Journal of the American Statistical Association, 53, pp. 789--798 (\url{https://lib.stat.cmu.edu/cmlib/src/cluster/fish.f})
100100

101101
Wand, M. P. 1995. Data-based choice of histogram binwidth. The American Statistician, 51, 59-64.
102102

0 commit comments

Comments
 (0)