Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with_rng_version() would be nice #90

Closed
gaborcsardi opened this issue Mar 27, 2019 · 3 comments · Fixed by #91
Closed

with_rng_version() would be nice #90

gaborcsardi opened this issue Mar 27, 2019 · 3 comments · Fixed by #91

Comments

@gaborcsardi
Copy link
Member

To ease fixing the new RNG madness in 3.6.0.

@gaborcsardi
Copy link
Member Author

I'll probably add an implementation to igraph tomorrow, because they make me fix this....

@gaborcsardi
Copy link
Member Author

Here is what I wrote:

with_rng_version <- function(version, expr) {
  orig <- RNGkind()
  on.exit(do.call(RNGkind, as.list(orig)), add = TRUE)
  suppressWarnings(RNGversion(version))
  expr
}

local_rng_version <- function(version, .local_envir = parent.frame()) {
  orig <- RNGkind()
  defer(do.call(RNGkind, as.list(orig)), envir = .local_envir)
  suppressWarnings(RNGversion(version))
  orig
}

I can submit a PR if you want to have this in withr.

@jimhester
Copy link
Member

jimhester commented May 2, 2019

A pr would be great!

gaborcsardi added a commit that referenced this issue May 3, 2019
`with_rng_version()` and `local_rng_version()`.

Closes #90.
jimhester pushed a commit that referenced this issue May 3, 2019
`with_rng_version()` and `local_rng_version()`.

Closes #90.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants