I am using R 4.2.1 on Windows 10, and I suspect the same issue also reproduces on CentoOS Linux 7 with the same R version. The save() load() sequence changes my list, why I cannot save my data into .RData file and later easily check the reproducibility of my results. For some reason, an arbitrary class definition is changed during the process as demonstrated below. How could I fix the problem or bypass it, to save and load data from hard drive and keep it exactly as it was? How about the newer R versions?
#The data is a "List of 13" having the size of 884Kb
identical(data, data) #TRUE
all.equal(data, data) #TRUE
data2 <- data
identical(data, data2) #TRUE
all.equal(data, data2) #TRUE
#Thus, moving the data to another variable does not change anything.
#However, saving to and loading from hard drive has an effect:
save(data, file="./test.RData")
#At this step it does not matter if I remove the "data" from the memory.
load("./test.RData")
identical(data, data2) #FALSE
all.equal(data, data2) #The output is below:
#[1] "Component \"model\": Attributes: < Component \"pp\": Class definitions are not identical >"
#[2] "Component \"model\": Attributes: < Component \"resp\": Class definitions are not identical >"
Below is a similar discussion, but here I demonstrated how the mere save() load() sequence changes the data (the class definitions more accurately): Determine Cause of `identical()` returning FALSE
Edit, here is a fully reproducible example:
library(lme4)
model <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
model2 <- model
identical(model, model2) #TRUE
all.equal(model, model2) #TRUE
save(model2, file="./test.RData")
load("./test.RData")
identical(model, model2) #FALSE
all.equal(model, model2) #The output is below
#[1] "Attributes: < Component “pp”: Class definitions are not identical >"
#[2] "Attributes: < Component “resp”: Class definitions are not identical >"
Okay, the easiest way to bypass the problem is to use
all.equal(data, data2, check.attributes = FALSE). However, the R should not change anything when the data is saved into hard drive and loaded back into memory. So, this is an open issue at least with the R version I use.Here is a link to the R documentation about the
all.equal():https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/all.equal