RNG R/Splus compatibility
Paul Gilbert
pgilbert@bank-banque-canada.ca
Thu, 06 May 1999 10:15:44 -0400
Here is a correction to one of the functions I posted yesterday, which did not
work correctly when kind was a list. With a null argument this function returns
current RNG and seed information. Otherwise, it sets the values and returns the
new settings. Thus, in a function one might
old <- set.RNG()
on.exit(set.RNG(old))
effective <- set.RNG(new) #(= new)
Another approach would be that used by par() (i.e. return the old settings) so
one would
old <- set.RNG(new)
on.exit(set.RNG(old))
effective <- set.RNG() #(= new)
Does anyone have thoughts on this?
Paul Gilbert
_________
set.RNG <- function(kind=NULL, seed=NULL, rnorm=NULL)
{# with a null argument this also serves as get.RNG so it is possible to
# old <- set.RNG()
# on.exit(set.RNG(old))
# set.RNG("default") can affect both kind and seed, but not rnorm
if (is.list(kind))
list(kind=RNGkind(kind$kind), seed=set.seed(kind$seed),
rnorm= set.RNORMtransform(kind$rnorm) )
else
list(kind=RNGkind(kind), seed=set.seed(seed),
rnorm=set.RNORMtransform(rnorm) )
}
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._