Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why object becomes different after save/load to/from RData?

I have a large ExpressionSet object (Bioconductor) named eset. Can you explain why this happens? Why the object's copy is not identical to the original one after save/load?

> e2=eset
> identical(e2,eset)
[1] TRUE
> save(e2,file="test.RData")
> rm(e2)
> e2 # just to check the removal
Error: object 'e2' not found
> load("test.RData")
> identical(e2,eset)
[1] FALSE

Are there other ways to check the identity of two objects?

If needed I'm working with R 2.15.1 under Windows 7.

like image 252
yuk Avatar asked Mar 28 '13 16:03

yuk


People also ask

How to save data as object in R?

To save data as an RData object, use the save function. To save data as a RDS object, use the saveRDS function. In each case, the first argument should be the name of the R object you wish to save. You should then include a file argument that has the file name or file path you want to save the data set to.

How do I save work in R?

You can also save the entire R console screen within the GUI by clicking on "Save to File..." under the menu "File." This saves the commands and the output to a text file, exactly as you see them on the screen.


1 Answers

Environments are one of a few R object types (connections are another) for which saving and loading aren't exact inverses.

e <- new.env()
f <- e
identical(e,f)
# [1] TRUE
save("f", file="f.Rdata")
rm(f)
load("f.Rdata")
identical(e,f)
# [1] FALSE

ExpressionSet objects contain an assayData slot, of class AssayData, which is described as a "container class defined as a class union of list and environment". Though I don't have eset installed on my computer, I'd guess that the assayData slots of eset and e2 make reference to different environments, causing identical(eset, e2) to return FALSE.

like image 101
Josh O'Brien Avatar answered Oct 28 '22 20:10

Josh O'Brien