user321627
user321627

Reputation: 2572

Why do objects in RStudio/R which display as 1 GB in size get saved by RData or RDS file formats at much larger sizes, even at no compression?

I currently have an list object in RStudio, which shows up in the Environment listing as 1.2 GB. However, when I save with the function saveRDS with compress = FALSE, the size of saved object shows up as nearly 4 GB.

Is the reporting of the size of my list object wrong or is something else happening? I thought that if an object took up a certain space in R, it should save at that same size without compression? I understand there are a few questions on Stackoverflow similar to this, but none seems to explain why it differs even with no compression.

Upvotes: 0

Views: 694

Answers (1)

James
James

Reputation: 66844

The calculation of the size of objects in R is complicated by the need for efficient memory management. Your list may contain elements that are not accounted for while in memory as they may be shared resources, but will need to be included when exported. The help file for object.size states that:

Exactly which parts of the memory allocation should be attributed to which object is not clear-cut. This function merely provides a rough indication: it should be reasonably accurate for atomic vectors, but does not detect if elements of a list are shared, for example. (Sharing amongst elements of a character vector is taken into account, but not that between character vectors in a single object.)

Upvotes: 1

Related Questions