[Rd] warnings() in R-devel: inherits from "warnings" - summary(warnings())
Martin Maechler
m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Tue Oct 31 12:00:54 CET 2023
A few minutes ago, I have committed (svn rev 85445)
to R-devel {R's development source code, https://svn.r-project.org/R/trunk/}
a change with NEWS entry
* warnings() now always inherits from "warnings" as documented,
newly also in the case of no warnings, where it previously
returned NULL.
In addition to changing the R code to follow the help page,
another plus is that now
summary(warnings())
in the case of *no* warnings, correctly does
R> summary(warnings())
no warnings
instead of in current (released) R
R> summary(warnings())
Length Class Mode
0 NULL NULL
In a few CRAN / Bioc packages authors had used checks
if( is.null(warnings()) )
which will no longer do what was intended, as
the condition will always be FALSEm
so we strongly recommend you replace all
is.null(warnings())
by length(warnings()) == 0
(which works the same in current *and* future R versions).
One package maintainer has already been alerted, as he had
stopifnot(is.null(warnings()))
at the end of his test script and needs to replace it.
Something like
summary(warnings())
stopifnot(length(warnings()) == 0)
maybe a good way to end *such* test R scripts (where you treat
warnings as errors in the end):
Show (a summary of) the warnings if there are, and still stop.
Otherwise, we now *can* recommend using
summary(warnings())
more generally,
and particularly useful sometimes after
options(nwarnings = 1e5) # to get practically all warnings
Best regards,
Martin
--
Martin Maechler
ETH Zurich and R Core team
More information about the R-devel
mailing list