5

I am building an R package and using data-raw and data to store a library of pre-defined RxODE models. This works very well.

However, the resulting .rda files change at every generation. Some models contain an R environment, and the serialization seems to contain a 'creation time' timestamp. This means every time the data/ directory is regenerated, all files have changed...

Is there some way to modify the serialization of an R environment to be reproducible?

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')) )
parasietje
  • 1,529
  • 8
  • 36
  • `new.env()` does not do the same thing when called twice, it creates a different environment, so your are saving different objects. – moodymudskipper Oct 01 '22 at 10:48

1 Answers1

0

very interesting question. There is an oddly behaviour:

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')) )

My output is FALSE in the first identical but TRUE in the second. I do not clearly know why. Also I'm using save.image instead of save, so I do not know if it suits you! Best!

LocoGris
  • 4,432
  • 3
  • 15
  • 30