with_seed | R Documentation |
with_seed()
runs code with a specific random seed and resets it afterwards.
with_preserve_seed()
runs code with the current random seed and resets it
afterwards.
with_seed(
seed,
code,
.rng_kind = NULL,
.rng_normal_kind = NULL,
.rng_sample_kind = NULL
)
local_seed(
seed,
.local_envir = parent.frame(),
.rng_kind = NULL,
.rng_normal_kind = NULL,
.rng_sample_kind = NULL
)
with_preserve_seed(code)
local_preserve_seed(.local_envir = parent.frame())
seed |
|
code |
|
.rng_kind , .rng_normal_kind , .rng_sample_kind |
|
.local_envir |
|
[any]
The results of the evaluation of the code
argument.
withr
for examples
# Same random values:
with_preserve_seed(runif(5))
with_preserve_seed(runif(5))
# Use a pseudorandom value as seed to advance the RNG and pick a different
# value for the next call:
with_seed(seed <- sample.int(.Machine$integer.max, 1L), runif(5))
with_seed(seed, runif(5))
with_seed(seed <- sample.int(.Machine$integer.max, 1L), runif(5))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.