| seed {rando} | R Documentation |
Random Seed Defining Functions
Description
Functions related to generating random seeds and utilising them for reproducibility.
Usage
gen_seed()
set_seed(seed)
fix_seed(reset = FALSE)
with_seed(seed, expression)
pull_seed(x)
Arguments
seed |
The random seed to be used |
reset |
Should the fixed seed be forced to reset |
expression |
expression to be evaluated |
x |
object to extract the |
Details
Random values are generated based on the current seed used by the R system. This means by deliberately setting a seed in R, we can make work reproducible.
Value
gen_seed() returns a single numeric value
with_seed() returns the value of the evaluated expression after
with the relevant seed as an attribute (if required)
pull_seed() returns a single numeric value
fix_seed() and set_seed() do not return anything
Functions
-
gen_seed: Generates a random seed, which can be used inset_seed() -
set_seed: Sets the current seed -
fix_seed: Resets the seed to re-run code -
with_seed: Evaluates the expression after setting the seed. IfseedisTRUE, then it first generates a seed usinggen_seed(). Results are output with theseedattached (if set).#' -
pull_seed: Extracts the seed used to generate the results ofwith_seed()
Examples
my_seed <- gen_seed()
set_seed(my_seed)
r_norm(n=10)
set_seed(my_seed)
r_norm(n=10)
fix_seed()
r_norm(n=3)
fix_seed()
r_norm(n=3)
fix_seed(reset=TRUE)
r_norm(n=3)
res <- with_seed(my_seed, r_norm(n = 10))
res
pull_seed(res)