From otoomet at gmail.com  Sun Feb  8 04:52:16 2015
From: otoomet at gmail.com (otoomet)
Date: Sat, 7 Feb 2015 19:52:16 -0800 (PST)
Subject: [Rd] Which function can change RNG state?
Message-ID: <1423367536855-4702935.post@n4.nabble.com>

Today I struggled for hours to understand some unexpected package test
results.  It turned out that this is because package "parallel", buried deep
in my dependencies, calls runif() during it's initialization and in this way
changes the random number sequence.   This seems to be a part of a more
general question--which kind of functions can we trust if we want to
preserve random numbers, and the rest of the environment, like graphical
parameters?    

One could put all the burden on the end user--never trust any of the calls
you make, it is your responsibility to save the RNG state if you wish. 
However, this might be very cumbersome if you have to do this around all
cat(), print() and similar calls that most likely will never tinker with
random numbers.   For instance, can I be sure that
set.seed(0); print(runif(1)); print(rnorm(1))
will always print the same numbers, also in the future version of R?  There
are also commands that we definitely expect to change the RNG state, like
random numbers, bootstrapping, etc.  I just did not expect that library() is
one of them...

I think it would be nice to have some sort of guidelines here.  The only
related sentence I am aware of is in the CRAN policy:
- Packages should not modify the global environment (user?s workspace). 

Any thoughts?

Cheers,
Ott



--
View this message in context: http://r.789695.n4.nabble.com/Which-function-can-change-RNG-state-tp4702935.html
Sent from the R devel mailing list archive at Nabble.com.



[Rd] Which function can change RNG state?
otoomet