简体   繁体   中英

Different results even with set.seed() in R

I have re-run with the same seed but cannot produce same results in R studio.

Will set.seed() lose track when calling different user packages, R6 classes and methods?

Have you come across similar situation and how to fix it?

Thanks a lot

closeAllConnections()
rm(list=ls())
gc()

set.seed(123456)
require(PackageA)  #user defined package

fileName <- "N:/Risk Management/abc.json";

configuration <- JsonConfigurationReader$readConfiguration(fileName); #R6 class and method in PackageA

instance <- someClass$new(configuration); #R6 class and method in PackageA

instance$execute()  #will produce some random numbers in this method

closeAllConnections()
rm(list=ls())
gc()

The issue would come if you are using diffrent R versions (3.5 vs 3.6 and above). The version upto 3.5 will show same results but for the same code the versions 3.6 will show a diffrent results. However version 3.6 and 4.0 will have same results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM