Skip to content

Commit 9aa278b

Browse files
authored
Merge pull request #43 from eblondel/main
support big.mark argument
2 parents 473e462 + b906999 commit 9aa278b

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

R/classInt.R

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ findCols <- function(clI, factor = FALSE) {
481481
# partition intervals are closed on the left or the right
482482
# Added dataPrecision for rounding of the interval endpoints
483483
tableClassIntervals <- function(cols, brks, under="under", over="over",
484-
between="-", digits = getOption("digits"), cutlabels=TRUE, intervalClosure=c("left", "right"), dataPrecision=NULL, unique=FALSE, var) {
484+
between="-", digits = getOption("digits"), cutlabels=TRUE, intervalClosure=c("left", "right"), dataPrecision=NULL, unique=FALSE, big.mark=NULL, var) {
485485
# Matthieu Stigler 120705 unique
486486
# Matthieu Stigler 120705
487487
intervalClosure <- match.arg(intervalClosure)
@@ -504,16 +504,16 @@ tableClassIntervals <- function(cols, brks, under="under", over="over",
504504

505505
#The two global endpoints are going through roundEndpoint to get
506506
# formatting right, nothing more
507-
if (cutlabels) nres[1] <- paste("[", roundEndpoint(brks[1], intervalClosure, dataPrecision), between, roundEndpoint(brks[2], intervalClosure, dataPrecision), right, sep=sep)
507+
if (cutlabels) nres[1] <- paste("[", roundEndpoint(brks[1], intervalClosure, dataPrecision, big.mark), between, roundEndpoint(brks[2], intervalClosure, dataPrecision, big.mark), right, sep=sep)
508508
else nres[1] <- paste(under, roundEndpoint(brks[2], intervalClosure, dataPrecision), sep=sep)
509509
for (i in 2:(lx - 2)) {
510-
if (cutlabels) nres[i] <- paste(left, roundEndpoint(brks[i], intervalClosure, dataPrecision), between, roundEndpoint(brks[i + 1], intervalClosure, dataPrecision), right,
510+
if (cutlabels) nres[i] <- paste(left, roundEndpoint(brks[i], intervalClosure, dataPrecision, big.mark), between, roundEndpoint(brks[i + 1], intervalClosure, dataPrecision, big.mark), right,
511511
sep=sep)
512-
else nres[i] <- paste(roundEndpoint(brks[i], intervalClosure, dataPrecision), between, roundEndpoint(brks[i + 1], intervalClosure, dataPrecision), sep=sep)
512+
else nres[i] <- paste(roundEndpoint(brks[i], intervalClosure, dataPrecision, big.mark), between, roundEndpoint(brks[i + 1], intervalClosure, dataPrecision, big.mark), sep=sep)
513513
}
514-
if (cutlabels) nres[lx - 1] <- paste(left, roundEndpoint(brks[lx - 1], intervalClosure, dataPrecision), between, roundEndpoint(brks[lx], intervalClosure, dataPrecision), "]",
514+
if (cutlabels) nres[lx - 1] <- paste(left, roundEndpoint(brks[lx - 1], intervalClosure, dataPrecision, big.mark), between, roundEndpoint(brks[lx], intervalClosure, dataPrecision, big.mark), "]",
515515
sep=sep)
516-
else nres[lx - 1] <- paste(over, roundEndpoint(brks[lx - 1], intervalClosure, dataPrecision), sep=sep)
516+
else nres[lx - 1] <- paste(over, roundEndpoint(brks[lx - 1], intervalClosure, dataPrecision, big.mark), sep=sep)
517517
tab <- table(factor(cols, levels=1:(lx - 1)))
518518
names(tab) <- nres
519519

@@ -538,7 +538,7 @@ tableClassIntervals <- function(cols, brks, under="under", over="over",
538538

539539
# change contributed by Richard Dunlap 090512
540540
# New helper method for tableClassIntervals
541-
roundEndpoint <- function(x, intervalClosure=c("left", "right"), dataPrecision) {
541+
roundEndpoint <- function(x, intervalClosure=c("left", "right"), dataPrecision, big.mark) {
542542
# Matthieu Stigler 120705
543543
intervalClosure <- match.arg(intervalClosure)
544544
if (is.null(dataPrecision)) {
@@ -551,11 +551,16 @@ roundEndpoint <- function(x, intervalClosure=c("left", "right"), dataPrecision)
551551
{
552552
retval <- floor(x * 10^dataPrecision) / 10^dataPrecision
553553
}
554+
555+
if(!missing(big.mark)) if(is.character(big.mark)) {
556+
retval <- prettyNum(retval, big.mark = big.mark)
557+
}
558+
554559
digits = getOption("digits")
555560
format(retval, digits=digits, trim=TRUE)
556561
} #FIXME output trailing zeros in decimals
557562

558-
print.classIntervals <- function(x, digits = getOption("digits"), ..., under="under", over="over", between="-", cutlabels=TRUE, unique=FALSE) {
563+
print.classIntervals <- function(x, digits = getOption("digits"), ..., under="under", over="over", between="-", cutlabels=TRUE, unique=FALSE, big.mark = NULL) {
559564
if (!inherits(x, "classIntervals")) stop("Class interval object required")
560565
cat("style: ", attr(x, "style"), "\n", sep="")
561566
UNITS <- attr(x, "var_units")
@@ -573,7 +578,7 @@ print.classIntervals <- function(x, digits = getOption("digits"), ..., under="un
573578
# change contributed by Richard Dunlap 090512
574579
# passes the intervalClosure argument to tableClassIntervals
575580
tab <- tableClassIntervals(cols=cols, brks=nbrks, under=under, over=over,
576-
between=between, digits=digits, cutlabels=cutlabels, intervalClosure=attr(x, "intervalClosure"), dataPrecision=attr(x, "dataPrecision"), unique=unique, nvar)
581+
between=between, digits=digits, cutlabels=cutlabels, intervalClosure=attr(x, "intervalClosure"), dataPrecision=attr(x, "dataPrecision"), unique=unique, big.mark = big.mark, var = nvar)
577582
print(tab, digits=digits, ...)
578583
invisible(tab)
579584
}

man/classIntervals.Rd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ classIntervals(var, n, style = "quantile", rtimes = 3, ...,
1616
gr = c("[", "]"))
1717
\method{plot}{classIntervals}(x, pal, ...)
1818
\method{print}{classIntervals}(x, digits = getOption("digits"), ...,
19-
under="under", over="over", between="-", cutlabels=TRUE, unique=FALSE)
19+
under="under", over="over", between="-", cutlabels=TRUE, unique=FALSE,big.mark=NULL)
2020
nPartitions(x)
2121
classIntervals2shingle(x)
2222
}
@@ -41,6 +41,7 @@ classIntervals2shingle(x)
4141
\item{digits}{minimal number of significant digits in printed table labels}
4242
\item{cutlabels}{default TRUE, use cut-style labels in printed table labels}
4343
\item{unique}{default FALSE; if TRUE, collapse labels of single-value classes}
44+
\item{big.mark}{default NULL; an object of class \code{character} to specify to 'thousands' separator}
4445
\item{pal}{a character vector of at least two colour names for colour coding the class intervals in an ECDF plot; \code{colorRampPalette} is used internally to create the correct number of colours}
4546
}
4647
\details{

0 commit comments

Comments
 (0)