When a .RData file is loaded same random numbers are generated everytime. For example try this: (Type these in terminal)
rm(list=ls())
x=10 #Just some random value
save.image("samplefile.RData")
Now try this:
rm(list=ls())
load("samplefile.RData")
print(runif(n=100,min=0,max=100)) #Now it prints same random numbers everytime i run above code junket.
Can anyone please explain?
Thanks.
This is intentional behaviour - .Random.seed is saved within Rdata file. If you want different data generated just rm() the value before that or set it to a different one.
If you need to load a .RData file that has a saved .Random.seed, you can reset the seed using the clock time and this bit of code:
a <- as.numeric(Sys.time())
set.seed(a)
Note that there are benefits to being able to exactly reproduce randomizations, i.e., reproducible research. But for everyday purposes it's probably safer to save and load objects rather than the environment. https://www.rdocumentation.org/packages/base/versions/3.4.0/topics/readRDS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With