R/utils_seed.R

Defines functions restore_seed

# Borrowed from https://github.com/r-lib/withr/blob/main/R/seed.R
# under the MIT license. See the NOTICE file in the targets package source.
restore_seed <- function(old_seed) {
  if_any(
    is.null(old_seed), {
      set.seed(seed = NULL)
      rm(list = ".Random.seed", envir = .GlobalEnv)
    },
    assign(x = ".Random.seed", value = old_seed, envir = .GlobalEnv)
  )
}

Try the targets package in your browser

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

targets documentation built on Oct. 12, 2023, 5:07 p.m.