[R-pkg-devel] Change in normal random numbers between R 3.5.3 and R 3.6.0
R. Mark Sharp
rm@h@rp @end|ng |rom me@com
Fri May 10 14:33:14 CEST 2019
Ulrike,
RNGkind() worked on 3.4.1 and 3.6.0 but generated a warning on R 3.5.3. The message follows:
checking whether package ‘nprcmanager’ can be installed ... WARNING
Found the following significant warnings:
Note: possible error in 'RNGkind(sample.kind = "Rounding")': unused argument (sample.kind = "Rounding")
See ‘/tmp/RtmpA4S3Ki/file32b81c218ac8/nprcmanager.Rcheck/00install.out’ for details.
Information on the location(s) of code generating the ‘Note’s can be
obtained by re-running with environment variable R_KEEP_PKG_SOURCE set
to ‘yes’.
Mark
R. Mark Sharp
rmsharp using me.com
> On May 9, 2019, at 11:39 PM, Ulrike Grömping <groemping using beuth-hochschule.de> wrote:
>
> Mark,
>
> I used
>
> if (getRversion()>="3.6.0") RNGkind(sample.kind="Rounding")
>
> And that works. Actually, using rnorm afterwards also yields the same random numbers.
> My question arose from the fact that I confused myself about the noLD output I was supposed to reproduce. Therefore, my problem should be entirely explained by Duncan Murdoch's initial explanation: the sample() change does not only lead to different results in discrete sampling but also to different results from random number calls for other functions (like rnorm).
>
> Best, Ulrike
>
> Am 10.05.2019 um 04:58 schrieb R. Mark Sharp:
>> I was dealing with a similar issue but in the context of getting the same unit test code to work on multiple versions of R in a Travis-CI build. It seems RNGkind(sample.kind="Rounding”) does not work prior to version 3.6 so I resorted to using version dependent construction of the argument list to set.seed() in do.call().
>>
>> I better solution will be greatly appreciated.
>>
>> #' Work around for unit tests using sample()
>> #'
>> #' @param seed argument to \code{set.seed}
>> set_seed <- function(seed = 1) {
>> version <- as.integer(R.Version()$major) + (as.numeric(R.Version()$minor) / 10.0)
>> if (version >= 3.6) {
>> args <- list(seed, sample.kind = "Rounding")
>> } else {
>> args <- list(seed)
>> }
>> suppressWarnings(do.call(set.seed, args))
>> }
>>
>> Mark
>>
>> R. Mark Sharp, Ph.D.
>> Data Scientist and Biomedical Statistical Consultant
>> 7526 Meadow Green St.
>> San Antonio, TX 78251
>> mobile: 210-218-2868
>> rmsharp using me.com
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> On May 9, 2019, at 12:45 PM, Duncan Murdoch <murdoch.duncan using gmail.com> wrote:
>>>
>>> On 09/05/2019 12:43 p.m., Ulrike Grömping wrote:
>>>> Hmmmh, but does that also apply if the sample.kind has been set to the
>>>> old version? I.e., would
>>>> if (getRversion()>="3.6.0") RNGkind(sample.kind="Rounding")
>>>> val <- 10
>>>> set.seed(val)
>>>> discard <- sample(1000, 100)
>>>> rnorm(36)
>>>> produce the same normal random numbers in 3.5.3 and 3.6.0? I would have
>>>> expected it to, but it seems to produce the same normal random numbers
>>>> as R version 3.6.0 in the previous version of the test code without the
>>>> RNGkind call.
>>> I'm not seeing that, but I'm not using the exact versions you tested. If I run your code in "R version 3.5.2 (2018-12-20)" and "R Under development (unstable) (2019-05-02 r76454)" I get this output from both:
>>>
>>>> if (getRversion()>="3.6.0") RNGkind(sample.kind="Rounding")
>>>> val <- 10
>>>> set.seed(val)
>>>> discard <- sample(1000, 100)
>>>> rnorm(36)
>>> [1] -0.4006375 -0.3345566 1.3679540 2.1377671 0.5058193 0.7863424 -0.9022119 0.5328970 -0.6458943 0.2909875 -1.2375945
>>> [12] -0.4561763 -0.8303227 0.3401156 1.0663764 1.2161258 0.7356907 -0.4812086 0.5627448 -1.2463197 0.3809222 -1.4304273
>>> [23] -1.0484455 -0.2185036 -1.4899362 1.1727063 -1.4798270 -0.4303878 -1.0516386 1.5225863 0.5928281 -0.2226615 0.7128943
>>> [34] 0.7166008 0.4402419 0.1588306
>>>
>>> Okay, I just installed 3.6.0, and I get the same values there. I don't see a Mac binary for 3.5.3, so I can't test that one.
>>>
>>> Duncan Murdoch
>>>
>>> ______________________________________________
>>> R-package-devel using r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>
>
> --
> ##############################################
> ## Prof. Ulrike Groemping
> ## FB II
> ## Beuth University of Applied Sciences Berlin
> ##############################################
> ## prof.beuth-hochschule.de/groemping
> ## Phone: +49(0)30 4504 5127
> ## Fax: +49(0)30 4504 66 5127
> ## Home office: +49(0)30 394 04 863
> ##############################################
>
More information about the R-package-devel
mailing list