I modified an example in the object.size help page to create a function I want to be able to run:
"mysize" <- function() { z <- sapply(ls(), function(w) object.size(get(w))) as.matrix(rev(sort(z))[1:5]) } mysize() When I test the lines inside the function it works fine: > z <- sapply(ls(), function(w) object.size(get(w))) > as.matrix(rev(sort(z))[1:5]) [,1] mat 166344288 mod 130794704 zidx 799664 wfidx 799664 megacap 799664 > But when I try to run the function, it produces an error: > "mysize" <- function() { + z <- sapply(ls(), function(w) object.size(get(w))) + as.matrix(rev(sort(z))[1:5]) + } > mysize() Error in rev(sort(z)) : error in evaluating the argument 'x' in selecting a method for function 'rev': Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 'x' must be atomic > It must be a variable scoping problem, but I am not sure how to tackle it. Thanks, Roger *************************************************************** This message is for the named person's use only. It may\...{{dropped:14}} ______________________________________________ R-help@r-project.org 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.