Object size calculation in R Studio (object.size vs. obj_size)

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)
# 8,000,128 B
# 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?

When this feature was built in RStudio, I would bet that there was no lobstr around. But even if there were a package that would do something like that, there is a good case to be made to use base R for that since you don't want to depend on third-party dependency for something like that.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.