简体   繁体   中英

Discrepancy between the size of an object using object.size and save

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM