[R] Size of an object in workspace

Henrik Bengtsson hb at stat.berkeley.edu
Tue Apr 24 19:13:52 CEST 2007


See ll() in R.oo (that is two L:s), e.g.

> ll()
  member data.class dimension objectSize
1 author  character         1        120
2 myfunc   function      NULL        512
3      x     matrix   c(3,11)        248
4      y      array  c(5,7,1)        264

ll() is quite flexible so you can create your on functions to query
objects for whatever properties you want.  It can also be passed to
subset():

> subset(ll(), objectSize > 250)
  member data.class dimension objectSize
2 myfunc   function      NULL        512
4      y      array  c(5,7,1)        264

Hope this help

Henrik


On 4/24/07, Horace Tso <Horace.Tso at pgn.com> wrote:
> Hi folks,
>
> Is there a function to show the size of an R object? eg. in Kbytes?
>
> Couple months ago Bendix Carstensen posted this marvelous little function lls(), which shows all objects in the current workspace by mode, class and 'size'. This is a wonderful enhancement to the build-in ls() already and I now have it sourced in my Rprofile.site at startup.
>
> The only drawback is, 'size' is just the length/dim of an object. For matrices and data frames this is good enough. But for a list, knowing how many elements in there doesn't help much. I need to know the totality of the content in a common unit, eg. byte.
>
> Thanks in advance.
>
> Horace
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list