Home > Mobile >  Discrepancy between the size of an object using object.size and save
Discrepancy between the size of an object using object.size and save

Time:01-22

I'd like to save an object in R which is a list. object.size() says it's about 4 Mb in size.

> object.size(myobject)
4027168 bytes

But when I save it to a file it comes out as 1.47 Gb!

> save(myobject, file = "./myobject.RData")
> file.info("./myobject.RData"))
                                                          size isdir mode               mtime               ctime
/Users/michaelflower/Desktop/results/myobject.RData 1466060674 FALSE  644 2023-01-21 22:00:49 2023-01-21 22:00:49
                                                                  atime uid gid         uname grname
/Users/michaelflower/Desktop/results/myobject.RData 2023-01-21 21:36:01 501  20 michaelflower  staff

Any idea how to work out what's going on?

CodePudding user response:

try obj_size from lobstr:: for better accuracy

I messed around with some simple lists containing data.frames

library(purrr)
library(lobstr)
longlist <- map(1:500,~iris)
object.size(longlist) #3.6mb
obj_size(longlist) # 11kb
save(longlist,file="longlist.Rdata") #50kb
save(longlist,file="longlist2.Rdata",compress = FALSE) # 2.7Mb
save(longlist,file="longlist3.Rdata",compression_level = 9) #18.8kb
save(longlist,file="longlist4.Rdata",compression_level = 1) #228.8kb
  • Related