可重复使用saveRDS环境

问题描述 投票:5回答:1

我建立的R包,并使用data-rawdata存储预先定义的RxODE模型库。这工作得很好。

然而,由此产生.rda文件更改为每一代。某些机型中包含的R环境和系列化似乎包含了“创建时间”时间戳。这意味着每次data/目录再生时间,所有的文件已经改变...

是否有某种方式来修改的R环境的系列化将重现?

storeFile <- function(file) {
  env <- new.env()
  fun <- function(x) {x+3}
  environment(fun) <- env

  save('fun', file = file, ascii=TRUE)
}

storeFile('fileA.rda')
storeFile('fileB.rda')
message("Files are identical? ", identical(readLines('fileA.rda'), readLines('fileB.rda')) )
r r-package binary-reproducibility
1个回答
0
投票

非常有趣的问题。有一个奇怪的现象:

storeFile <- function(file) {

  env <- new.env()
  fun <- function(x) {x+3}
  environment(fun) <- env

  save.image(file = file, ascii=TRUE)
}


storeFile('fileA.rda')
storeFile('fileB.rda')
message("Files are identical? ", identical(readLines('fileA.rda'), readLines('fileB.rda')) )


storeFile('fileA.rda')
storeFile('fileB.rda')
message("Files are identical? ", identical(readLines('fileA.rda'), readLines('fileB.rda')) )

我的输出是FALSE在第一相同但TRUE在第二位。我不是很清楚为什么。另外我使用save.image而不是保存,因此,如果它适合你,我不知道!最好!

© www.soinside.com 2019 - 2024. All rights reserved.