[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 04:58:47 CEST 2019
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
More information about the R-package-devel
mailing list