I am currently working through Advanced R and came across the lobstr::obj_size
function which correctly calculates the size of an object by taking into account whether the same object has been referenced multiple times, e.g.
x <- runif(1e6)
y <- list(x, x, x)
obj_size(y)
# 8,000,128 B
object.size(y)
# 24000224 bytes
In the Environment pane in R Studio the size of y
is listed as 22.9 Mb, similar to object.size(y)
. Is there a reason for this? Wouldn't it be better to show the size one gets with obj_size(y)
since this is more accurate?