inst/testthat/helper_misc.R

with_seed = function(seed, expr) {
  old_seed = get0(".Random.seed", globalenv(), mode = "integer", inherits = FALSE)
  if (is.null(old_seed)) {
    runif(1L)
    old_seed = get0(".Random.seed", globalenv(), mode = "integer", inherits = FALSE)
  }

  on.exit(assign(".Random.seed", old_seed, globalenv()), add = TRUE)
  set.seed(seed)
  force(expr)
}

with_future = function(backend, expr, ...) {
  requireNamespace("future")
  oplan = force(future::plan(backend, ...))
  on.exit(future::plan(oplan), add = TRUE)
  force(expr)
}

private = function(x) {
  x[[".__enclos_env__"]][["private"]]
}

Try the mlr3 package in your browser

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

mlr3 documentation built on Nov. 17, 2023, 5:07 p.m.