Skip to content

Commit

Permalink
Revise code of set_seed.
Browse files Browse the repository at this point in the history
  • Loading branch information
0liver0815 committed Sep 14, 2023
1 parent 452d89c commit 1cfdf31
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions R/Design-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,21 @@ set_seed <- function(seed = NULL) {
runif(1)
}

if (is.null(seed)) {
rng_state <- get(".Random.seed", envir = .GlobalEnv)
rng_state <- if (is.null(seed)) {
get(".Random.seed", envir = .GlobalEnv)
} else {
r_seed <- get(".Random.seed", envir = .GlobalEnv)
# Make sure r_seed exists in parent frame.
assign("r_seed", r_seed, envir = parent.frame())
assign(".r_seed", r_seed, envir = parent.frame())
set.seed(seed)
rng_state <- structure(seed, kind = as.list(RNGkind()))
do.call("on.exit",
list(quote(assign(".Random.seed", r_seed, envir = .GlobalEnv))),
# Here we need the r_seed in the parent.frame!
do.call(
"on.exit",
list(quote(assign(".Random.seed", .r_seed, envir = .GlobalEnv))),
envir = parent.frame()
)
# Here we need the r_seed in the parent.frame!
structure(seed, kind = as.list(RNGkind()))
}

return(rng_state)
}

## get_result_list ----
Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ reference:
- plotDualResponses
- plotGain
- probit
- setSeed
- set_seed
- show,DualSimulationsSummary-method
- show,GeneralSimulationsSummary-method
- show,PseudoDualSimulationsSummary-method
Expand Down

0 comments on commit 1cfdf31

Please sign in to comment.