[Rd] [External] Re: rpois(9, 1e10)
Martin Maechler
m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Thu Jan 23 19:35:49 CET 2020
>>>>> Benjamin Tyner
>>>>> on Thu, 23 Jan 2020 08:16:03 -0500 writes:
> 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)
> )
Well, some people are too picky...
use numeric(), not integer() in such cases :
> vapply(1:10, function(i) if(runif(1) < 0.5) 1L else 2, FUN.VALUE=pi)
[1] 1 1 2 2 2 2 1 1 2 1
>
No, really, I don't plan to spend time "bloating" the
documentation any further,
when noticing that only a "few parts in a billion" people carefully read
our help pages where the remaining 99.999% percent rather try
things in the R console and draw (often) wrong conclusions...
I *am* glad and grateful for careful and accurate R users and
bug-squashing helpers such as you or Suharto or ...
Martin
> # 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