[Rd] [External] Re: rpois(9, 1e10)
Benjamin Tyner
btyner @end|ng |rom gm@||@com
Thu Jan 23 14:16:03 CET 2020
On 1/20/20 12:33 PM, Martin Maechler wrote:
>
> It's really something that should be discussed (possibly not
> here, .. but then I've started it here ...).
>
> The NEWS for R 3.0.0 contain (in NEW FEATURES) :
>
> * Functions rbinom(), rgeom(), rhyper(), rpois(), rnbinom(),
> rsignrank() and rwilcox() now return integer (not double)
> vectors. This halves the storage requirements for large
> simulations.
>
> and what I've been suggesting is to revert this change
> (svn rev r60225-6) which was purposefully and diligently done by
> a fellow R core member, so indeed must be debatable.
>
> Martin
For the record, I don't personally objects to the change here (as my
philosophy tends toward treating most warnings as errors anyway) but for
the sake of other useRs who may get bitten, perhaps we should be more
explicit that backwards-compatibility won't be preserved under certain
use patterns, for example:
# works (with warning) in R 3.6.2 but fails (with error) in R-devel:
vapply(list(1e9, 1e10),
function(lambda) {
rpois(1L, lambda)
},
FUN.VALUE = integer(1L)
)
# in R-devel, a little extra work to achieve a warning as before:
vapply(list(1e9, 1e10),
function(lambda) {
tmp <- rpois(1L, lambda)
if (!is.integer(tmp)) {
warning("NAs produced")
tmp <- NA_integer_
}
tmp
},
FUN.VALUE = integer(1L)
)
(and yes I realize that rpois() vectorizes on lambda, so vapply is
re-inventing the wheel in this toy example, but there could be (?) a
justified use for it in more complicated simulations).
More information about the R-devel
mailing list