Description Usage Arguments Details Value Examples
A set.seed
-wrapper to simplify reproducible coding.
1 2 3 |
seed |
The integer to be used as the seed value. This
argument will be given to the ordinary
|
expr |
An expression, default |
envir |
The environment in which |
kind |
Character or |
normal.kind |
Character string or |
vstr |
A character string containing a version number of
R. The default value |
create_kind_vstr_list |
Logical value, default |
create_code |
Logical value, default |
This function wraps around the function set.seed
,
RNGversion
-function such that all the details related to
kind
, normal.kind
and vstr
are fixed by
this single function. Moreover, it's also possible to return
the code for calling this function (with the default values
used) in order to ensure that computational scripts properly
reflect the settings under which they initially were used.
Finally, it's also possible to use this function to create a
list of the present settings, such that these can be integrated
into call of functions that are stored in order to ensure
reproducibility. See the help-page of Random
for
details about the three arguments kind
,
normal.kind
and vstr
.
The result depends on the value given to
create_code
. It will either be a setting of the seed, or
it will be the code needed to set the seed. NOTE: The function
will ensure that the settings for kind
and
normal.kind
will be reverted to the original ones. The
value of the .Random.seed
-vector will also depend upon
this. If kind
and normal.kind
was different from
the existing values, the value of .Random.seed
will be
reverted back to what it was when the function was called.
Otherwise, the Random.seed
-vector will be similar to
what it would have been if set.seed
and the expression
expr
had been evaluated in the workspace.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | ## Gives the same effect as 'set.seed'.
set.seed(seed = 1)
rnorm(3)
.a <- .Random.seed
set_seed(seed = 1)
rnorm(3)
.b <- .Random.seed
identical(.a, .b)
## The 'expr'-argument is evaluated in the global environment,
## unless otherwise specified by the 'envir'-argument.
set_seed(seed = 1,
expr = {.tmp <- rnorm(3)})
.tmp
.c <- .Random.seed
identical(.a, .c)
## No footprint on workspace when a change of RNG has been used.
set.seed(NULL)
.a <- .Random.seed
set_seed(seed =1,
expr = {.tmp <- rnorm(3)},
vstr = "1.0.0")
.tmp
.b <- .Random.seed
identical(.a, .b)
## No footprint on workspace when a list is produced.
set.seed(NULL)
.a <- .Random.seed
set_seed(seed =1,
expr = {.tmp <- rnorm(3)},
vstr = "1.0.0",
create_kind_vstr_list = TRUE)
.tmp
.b <- .Random.seed
identical(.a, .b)
## No footprint on workspace when code is produced.
set.seed(NULL)
.a <- .Random.seed
.seed <- 1
set_seed(seed = .seed,
expr = {.tmp__ <- rnorm(3)},
vstr = "1.0.0",
create_code = TRUE)
.b <- .Random.seed
identical(.a, .b)
## Note: The creation of the code does not evaluate
## the 'expr'-argument.
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.