-
Notifications
You must be signed in to change notification settings - Fork 16
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
Isolate random seed for cachem #29
Comments
@torfason I made a quick PR. If you could test it out, I'd appreciate it. Also, if you are able to figure out how to test it in the Rcpp case mentioned in the PR, that would be very helpful, although I can understand if it's too esoteric -- I can't remember the details myself even though I wrote all of that. |
The PR looks great to me, fixes all the cases that I had handy. I'm afraid, though, that I won't be of much use regarding the Rcpp case. I haven't done c/c++ bindings at all, and that discussion in the For what it's worth, I did a quick and dirty incorporation of RNG state tests into the full test suite. With those changes (see https:/torfason/cachem/tree/random-seed-tests - didn't do a PR), 10 tests fail on the
Not sure if it is attractive to use this approach in the main repo, but if so, it could be done with minimal clutter. Apart from Also, I can continue to be on the lookout for any strangeness regarding this, although my own code is pretty straight-forward R code, so if the tests don't trigger any Rcpp issues, I don't think it's likely that my regular code would do that. Thanks for responding so quickly! |
It is a widespread practice to rely on
set.seed()
to construct pseudo-random sets of analyses, but in a reproducible manner.Some functions within the
cachem
package modify this seed, but it is not obvious to users of the package that they should do so. This can (and did in my case) lead to unexpected and hard to debug behavior when cachem is introduced into such analysis directly or through intermediate packages that rely oncachem
for its effectiveness as a caching library.The issue can be demonstrated with a simple reprex:
The above also demonstrates that seed updates depend on the type of the cache, which can further complicate things (something that works with a memory cache can stop working when switching to a layered or disk cache).
My suggested fix would be to isolate the usage of the random seed wherever
cachem
needs access to randomness, so that the global seed is not affected by calls tocachem
functions.A discussion of this issue can be found here:
And an implementation of this within the
shiny
package (which is the approach I would recommend) can be found here:I'd be happy to discuss the best approach to this fix/enhancement, and provide an eventual pull request if it seems like it would be well-received.
The text was updated successfully, but these errors were encountered: