For reasons that are best known to myself [ ;-) ] I have a value of .Random.seed saved (via dput()) in a file ``.Random.seed.save''. In my .Rprofile I have the lines: .Random.seed <- dget(".Random.seed.save") Junk <- dget(".Random.seed.save") print(all.equal(.Random.seed,dget(".Random.seed.save"))) print(all.equal(Junk,dget(".Random.seed.save"))) The two calls to all.equal() both return TRUE. However when I repeat the calls from the command line after the R session has started, I get TRUE from the second (``Junk'') call but [1] "Mean relative difference: 0.1" from the first. The value of .Random.seed appears to be that which was there when I quit the previous R session and not the one that I tried to read in from the file. If I *remove* .Random.seed before quitting (and save the workspace, so that there is no .Random.seed in .RData then I get TRUE from both calls to all.equal() made from the command line. I.e. the value of .Random.seed ***is*** the one read in from the file. Can anyone: (a) Explain what's going on? (b) Suggest how I might arrange that the value of .Random.seed be made equal to that read in from the file? ***PLEASE*** don't tell me to use set.seed() instead, or something like that. I ***know*** about set.seed() --- I wasn't born yesterday, y'know! Please just accept that I want to do what I want to do, and (if you can) tell me how. Ta. cheers, Rolf Turner ###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
Charles C. Berry
2008-Aug-20 22:21 UTC
[R] Reading in a value of .Random.seed in .Rprofile
On Thu, 21 Aug 2008, Rolf Turner wrote:> > > For reasons that are best known to myself [ ;-) ] I have a value of > .Random.seed > saved (via dput()) in a file ``.Random.seed.save''. > > In my .Rprofile I have the lines: > > .Random.seed <- dget(".Random.seed.save") > Junk <- dget(".Random.seed.save") > print(all.equal(.Random.seed,dget(".Random.seed.save"))) > print(all.equal(Junk,dget(".Random.seed.save"))) > > The two calls to all.equal() both return TRUE. > > However when I repeat the calls from the command line after the > R session has started, I get TRUE from the second (``Junk'') call > but > > [1] "Mean relative difference: 0.1" > > from the first.Not on my computer. I get TRUE twice whether at start up, source()ing .Rprofile, or C-c C-n'ing the lines from emacs ESS. I have to type load(".RData") _after_ startup to get behavior like you describe. Perhaps, you have something later in your .Rprofile that specifically load()'s your old .RData? Chuck p.s.> sessionInfo()R version 2.7.1 (2008-06-23) x86_64-unknown-linux-gnu locale: C attached base packages: [1] stats graphics grDevices utils datasets methods base -- Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
Hi Rolf: I think this is a case of RTFM. ?.Rprofile tells you that the profile is executed before the workspace is restored. Initially I thought this might be similar to bug PR#12567 that I filed this week, but now I think not necessarily. Cheers, Ray On Thu, 21 Aug 2008, Rolf Turner wrote:> For reasons that are best known to myself [ ;-) ] I have a value > of .Random.seed > saved (via dput()) in a file ``.Random.seed.save''. > > In my .Rprofile I have the lines: > > .Random.seed <- dget(".Random.seed.save") > Junk <- dget(".Random.seed.save") > print(all.equal(.Random.seed,dget(".Random.seed.save"))) > print(all.equal(Junk,dget(".Random.seed.save"))) > > The two calls to all.equal() both return TRUE. > > However when I repeat the calls from the command line after the > R session has started, I get TRUE from the second (``Junk'') call > but > > [1] "Mean relative difference: 0.1" > > from the first. > > The value of .Random.seed appears to be that which was there when I quit > the previous R session and not the one that I tried to read in from > the file. > > If I *remove* .Random.seed before quitting (and save the workspace, > so that > there is no .Random.seed in .RData then I get TRUE from both calls to > all.equal() made from the command line. I.e. the value of .Random.seed > ***is*** the one read in from the file. > > Can anyone: > > (a) Explain what's going on? > > (b) Suggest how I might arrange that the value of .Random.seed be > made equal to that read in from the file? > > ***PLEASE*** don't tell me to use set.seed() instead, or something > like that. > I ***know*** about set.seed() --- I wasn't born yesterday, y'know! > Please just > accept that I want to do what I want to do, and (if you can) tell me > how. > > Ta. > > cheers, > > Rolf Turner > > > ###################################################################### > Attention:\ This e-mail message is privileged and confid...{{dropped:9}} > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html and provide commented, minimal, > self-contained, reproducible code.