On Wed, Jul 1, 2009 at 3:02 AM, gug <guygr...@netvigator.com> wrote:

>
>      sapply(ls(), function(x) object.size(get(x)))
> -This lists all objects with the memory each is using (I should be honest
> and say that, never having used "sapply" before, I don't truly understand
> the syntax of this, but it seems to work).
>

In this particular case (getting the size of each object in the global
environment) you can also do:

eapply(.GlobalEnv, object.size)
# or eapply(.GlobalEnv, object.size, all.names=TRUE) , see ?eapply

Eapply applies a function (here:object.size) to every object in an
environment; with `sapply` you first use ls() to get the names of all
objects as a character vector, and then you need `get` because you probably
want the sizes of objects themselves, not their names -- so it can't be
just  sapply(ls(), object.size) .

Regards,

Kenn

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to