| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/rng.R |
| 3 |
\name{with_rng_version} |
| 4 |
\alias{with_rng_version} |
| 5 |
\alias{local_rng_version} |
| 6 |
\title{RNG version} |
| 7 |
\usage{ |
| 8 |
with_rng_version(version, code) |
| 9 |
|
| 10 |
local_rng_version(version, .local_envir = parent.frame()) |
| 11 |
} |
| 12 |
\arguments{ |
| 13 |
\item{version}{\verb{[character(1)]} an R version number, e.g. |
| 14 |
\code{"3.5.0"}, to switch to the RNG this version of R uses. |
| 15 |
See \code{\link[=RNGversion]{RNGversion()}}.} |
| 16 |
|
| 17 |
\item{code}{\code{[any]}\cr Code to execute in the temporary environment} |
| 18 |
|
| 19 |
\item{.local_envir}{The environment to apply the change to.} |
| 20 |
} |
| 21 |
\value{ |
| 22 |
\code{[any]}\cr The results of the evaluation of the \code{code} |
| 23 |
argument. |
| 24 |
} |
| 25 |
\description{ |
| 26 |
Change the RNG version and restore it afterwards. |
| 27 |
} |
| 28 |
\details{ |
| 29 |
\code{with_rng_version()} runs the code with the specified RNG version and |
| 30 |
resets it afterwards. |
| 31 |
|
| 32 |
\code{local_rng_version()} changes the RNG version for the caller |
| 33 |
execution environment. |
| 34 |
} |
| 35 |
\examples{ |
| 36 |
RNGkind() |
| 37 |
with_rng_version("3.0.0", RNGkind()) |
| 38 |
with_rng_version("1.6.0", RNGkind()) |
| 39 |
|
| 40 |
with_rng_version("3.0.0", |
| 41 |
with_seed(42, sample(1:100, 3))) |
| 42 |
|
| 43 |
with_rng_version("1.6.0", |
| 44 |
with_seed(42, sample(1:100, 3))) |
| 45 |
|
| 46 |
RNGkind() |
| 47 |
|
| 48 |
fun1 <- function() { |
| 49 |
local_rng_version("3.0.0") |
| 50 |
with_seed(42, sample(1:100, 3)) |
| 51 |
} |
| 52 |
|
| 53 |
fun2 <- function() { |
| 54 |
local_rng_version("1.6.0") |
| 55 |
with_seed(42, sample(1:100, 3)) |
| 56 |
} |
| 57 |
|
| 58 |
RNGkind() |
| 59 |
fun1() |
| 60 |
fun2() |
| 61 |
RNGkind() |
| 62 |
} |
| 63 |
\seealso{ |
| 64 |
\code{\link{withr}} for examples |
| 65 |
|
| 66 |
\code{\link[=RNGversion]{RNGversion()}}, \code{\link[=RNGkind]{RNGkind()}}, \code{\link[=with_seed]{with_seed()}}. |
| 67 |
} |