-
Notifications
You must be signed in to change notification settings - Fork 39
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
withr::with_preserve_seed() does not preserve is.null(.Random.seed) #124
Comments
I'm not sure it's even possible to preserve a NULL random seed. Can we solve this by documentation? |
Sorry, I wasn't clear. The value is not BTW, I'd say it's not sufficient to document. A real-world problem where $ R --quiet --vanilla
> exists(".Random.seed", envir = .GlobalEnv)
[1] FALSE
> library(ggplot2)
> exists(".Random.seed", envir = .GlobalEnv)
[1] TRUE It's an unfortunate side effect that loading/attaching a package causes an update to the RNG state. It prevents certain type of RNG validations. (This is actually how I tracked it down). |
#125 should fix this, after that change we have the following behavior (run in an interactive session so that the ggplot onAttach code would trigger) exists(".Random.seed", envir = .GlobalEnv)
#> [1] FALSE
library(ggplot2)
exists(".Random.seed", envir = .GlobalEnv)
#> [1] FALSE |
Yes, LGTM. Thxs. Not sure when you want to close this issue, so I leave that to you. |
* Restore an unset `.Random.seed` Fixes #124 * Move tests * Tweak and add test Co-authored-by: Kirill Müller <krlmlr@users.noreply.github.com>
Example:
$ Rscript --vanilla -e "str(.GlobalEnv$.Random.seed); withr::with_preserve_seed(x <- sample.int(1L)); str(.GlobalEnv$.Random.seed)" NULL int [1:626] 10403 1 1586168631 257966637 -1833262268 2037450858 175878869 786533487 163480950 -2036568416 ...
The text was updated successfully, but these errors were encountered: