Skip to content
Prev 3875 / 12125 Next

[R-pkg-devel] Change in normal random numbers between R 3.5.3 and R 3.6.0

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 at me.com