[R] Using object.size inside a function
    Bos, Roger 
    roger.bos at rothschild.com
       
    Tue Apr 13 14:43:39 CEST 2010
    
    
  
When I encounter memory errors, I like to see the size of the objects in
memory, so I modified one of the examples:
    z <- sapply(ls(), function(x) object.size(get(x)))
    as.matrix(rev(sort(z))[1:10])
This works fine if I run it as is, but if I try to place it inside a
function, I get an error (see below).  I tried using sort.list and
unlist, but I couldn't get it to work.  I don't understand why the
commands work by themselves but not in a function.  Its probably a
simple fix, can anyone enlighten me?
Thanks, Roger.
> "mysize" <- function() {
+     z <- sapply(ls(), function(x) object.size(get(x)))
+     as.matrix(rev(sort(z))[1:10])
+ }
> mysize()
Error in sort.list(z) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?
> 
***************************************************************
This message is for the named person's use only. It may\...{{dropped:20}}
    
    
More information about the R-help
mailing list