R/read.R
When a project is created with make()
or drake_config()
, the project's pseudo-random number generator
seed is cached. Then, unless the cache is destroyed,
the seeds of all the targets will deterministically depend on
this one central seed. That way, reproducibility is protected,
even under randomness.
read_drake_seed(path = getwd(), search = TRUE, cache = NULL, verbose = drake::default_verbose())
path | Root directory of the drake project,
or if |
---|---|
search | logical. If |
cache | drake cache. See |
verbose | logical or numeric, control printing to the console.
Use
|
An integer vector.
cache <- storr::storr_environment() # Just for the examples. my_plan <- drake_plan( target1 = sqrt(1234), target2 = rnorm(n = 1, mean = target1) ) tmp <- runif(1) # Needed to get a .Random.seed, but not for drake. digest::digest(.Random.seed) # Fingerprint of the current R session's seed.#> [1] "5b720f218bf72fb5ac8f351100af5c60"#>#>#> [1] "5b720f218bf72fb5ac8f351100af5c60"# Drake uses a hard-coded seed if you do not supply one. read_drake_seed(cache = cache)#> [1] 0#> [1] 33.8988clean(target2, cache = cache) # Oops, I removed the data! tmp <- runif(1) # Maybe the R session's seed also changed. make(my_plan, cache = cache) # Rebuild target2.#>#> #>#># Same as before: read_drake_seed(cache = cache)#> [1] 0#> [1] 33.8988# You can also supply a seed. # If your project already exists, it must agree with the project's # preexisting seed (default: 0) clean(target2, cache = cache) make(my_plan, cache = cache, seed = 0)#>#> #>#>read_drake_seed(cache = cache)#> [1] 0#> [1] 33.8988# If you want to supply a different seed than 0, # you need to destroy the cache and start over first. clean(destroy = TRUE, cache = cache) cache <- storr::storr_environment() # Just for the examples. make(my_plan, cache = cache, seed = 1234)#>#> #>#>#>read_drake_seed(cache = cache)#> [1] 1234#> [1] 34.52217