R/set_test_seed.R

Defines functions set_test_seed

Documented in set_test_seed

#' @title Set random seed for unit tests
#' @description
#'  \Sexpr[results=rd, stage=render]{lifecycle::badge("experimental")}
#'
#'  In order for tests to be compatible with \code{R} versions \code{< 3.6.0},
#'  we set the \code{sample.kind} argument in \code{\link[base:Random]{set.seed()}}
#'  to \code{"Rounding"} when using \code{R} versions \code{>= 3.6.0}.
#' @param seed Random \code{seed}.
#' @param ... Named arguments to \code{\link[base:Random]{set.seed()}}.
#' @author Ludvig Renbo Olsen, \email{r-pkgs@@ludvigolsen.dk}
#' @author R. Mark Sharp
#' @return \code{NULL}.
#' @export
#' @details
#'  Initially contributed by R. Mark Sharp (github: @@rmsharp).
set_test_seed <- function(seed = 42, ...) {
  if ((getRversion()$major == 3 &&
       getRversion()$minor >= 6) ||
      getRversion()$major > 3) {
    args <- list(seed, sample.kind = "Rounding", ...)
  } else {
    args <- list(seed, ...)
  }
  suppressWarnings(do.call(set.seed, args))
}

Try the xpectr package in your browser

Any scripts or data that you put into this service are public.

xpectr documentation built on Nov. 18, 2022, 5:10 p.m.