Skip to content

Commit aeb2fe5

Browse files
author
maechler
committed
correct warning message in some hist(*, plot=FALSE) cases
git-svn-id: https://svn.r-project.org/R/trunk@88472 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent b566515 commit aeb2fe5

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/library/graphics/R/hist.R

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ hist.default <-
9797
nB <- as.integer(nB)
9898
if(is.na(nB)) stop("invalid length(breaks)")
9999

100-
## Do this *before* adding fuzz or logic breaks down...
100+
## Do this *before* adding fuzz or logic breaks down ..
101101

102102
h <- as.double(diff(breaks))
103103
equidist <- !use.br || diff(range(h)) < 1e-7 * mean(h)
@@ -145,18 +145,25 @@ hist.default <-
145145
}
146146
else { ## plot is FALSE
147147
if (warn.unused) {
148-
## make an effort to warn about "nonsensical" arguments:
148+
## make an effort to warn about "nonsensical" arguments, notably those only in plot(.) above
149149
nf <- names(formals()) ## all formals but those:
150150
nf <- nf[is.na(match(nf, c("x", "breaks", "nclass", "plot",
151151
"include.lowest", "right", "fuzz")))]
152152
missE <- lapply(nf, function(n)
153153
substitute(missing(.), list(. = as.name(n))))
154154
not.miss <- ! vapply(missE, eval, NA, envir = environment())
155+
nf <- nf[not.miss]
156+
nnmiss <- sum(not.miss)
157+
if(any(iM <- nf == "...")) { # replace "..." with arg names in `...`
158+
dnms <- ...names()
159+
nf <- c(nf[!iM], dnms)
160+
nnmiss <- nnmiss -1L + length(dnms)
161+
}
155162
if(any(not.miss))
156-
warning(sprintf(ngettext(sum(not.miss),
163+
warning(sprintf(ngettext(nnmiss,
157164
"argument %s is not made use of",
158165
"arguments %s are not made use of"),
159-
paste(sQuote(nf[not.miss]), collapse=", ")),
166+
paste(sQuote(nf), collapse=", ")),
160167
domain = NA)
161168
}
162169
r

tests/reg-tests-1e.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,7 @@ assertWarnV(options(scipen = -100))# warns and sets to min = -9
16101610
stopifnot(identical(getOption("scipen"), -9L))
16111611
assertWarnV(options(scipen = 100000))# warns and sets to max = 9999
16121612
stopifnot(identical(getOption("scipen"), 9999L))
1613+
options(scipen=scipenO) # revert
16131614
## setting to NULL would invalidate as.character(Sys.time())
16141615

16151616

@@ -2047,9 +2048,7 @@ assertValueIs("1")
20472048

20482049

20492050
## No warnings for hist(.., log="x") -- PR#18921
2050-
op <- options(warn = 2)
20512051
hist(1:100, breaks = 2^(0:8), log = "x")
2052-
options(op)
20532052
## used to signal 3 warnings
20542053

20552054

@@ -2084,6 +2083,18 @@ stopifnot(is.list(Ldt), vapply(Ldt, inherits, NA, "Date"),
20842083
# fD was "11100" "11101" .... "11111" in R <= 4.5.z
20852084

20862085

2086+
## hist(*, plot=FALSE) warning about "nonsensical" arguments
2087+
hiW <- getVaW(hist(1:22, log = "x", plot = FALSE))
2088+
hi. <- hist(1:22, log = "x", plot = FALSE, warn.unused = FALSE) # no warning
2089+
noA <- \(x) `attributes<-`(x, NULL)
2090+
stopifnot(exprs = {
2091+
nzchar(print(wmsg <- attr(hiW,"warning")))
2092+
grepl(sQuote("log"), wmsg)
2093+
identical(noA(hiW), noA(hi.))
2094+
})
2095+
## warning msg confusingly had '...' instead of 'log'
2096+
2097+
20872098

20882099
## keep at end
20892100
rbind(last = proc.time() - .pt,

0 commit comments

Comments
 (0)