[R] Summary of Total Object.Size in R Script
Henrik Bengtsson
hb at stat.berkeley.edu
Thu Jan 15 16:55:20 CET 2009
See also ll() in the R.oo package, e.g.
# To list all objects in .GlobalEnv:
ll()
member data.class dimension objectSize
1 *tmp* Person 1 428
2 as.character.Person function NULL 1208
3 country character 1 44
4 equals.Person function NULL 2324
5 filename character 1 84
6 getAge function NULL 372
7 getAge.Person function NULL 612
8 getName.Person function NULL 628
9 hashCode.Person function NULL 1196
10 last.warning list 1 192
11 obj Person 1 428
12 Person Class NULL 2292
13 setAge function NULL 372
14 setAge.Person function NULL 2088
15 setName function NULL 372
16 setName.Person function NULL 760
17 staticCode.Person function NULL 2372
# To list all functions in the methods package:
ll(mode="function", envir="methods")
# To list all numeric and character object in the base package:
ll(mode=c("numeric", "character"), envir="base")
# To list all objects in the base package greater than 40kb:
subset(ll(envir="base"), objectSize > 40000)
ll() takes argument 'properties', which allows you to construct any
column property you ever like. There is also a 'sortBy' argument.
See help(ll) for more details.
/Henrik
On Thu, Jan 15, 2009 at 3:00 AM, Gundala Viswanath <gundalav at gmail.com> wrote:
> Sorry for my late reply.
>
> Thank you so much Jim. This script of yours
> is very2 useful. I have used it.
>
> - Gundala Viswanath
> Jakarta - Indonesia
>
>
>
> On Wed, Jan 14, 2009 at 12:17 AM, jim holtman <jholtman at gmail.com> wrote:
>> Here is a function I use to see how big the objects in my workspace are:
>>
>>> my.ls <-
>> + function (pos = 1, sorted = F)
>> + {
>> + .result <- sapply(ls(pos = pos, all.names = TRUE), function(..x)
>> object.size(eval(as.symbol(..x))))
>> + if (sorted) {
>> + .result <- rev(sort(.result))
>> + }
>> + .ls <- as.data.frame(rbind(as.matrix(.result), `**Total` = sum(.result)))
>> + names(.ls) <- "Size"
>> + .ls$Size <- formatC(.ls$Size, big.mark = ",", digits = 0,
>> + format = "f")
>> + .ls$Mode <- c(unlist(lapply(rownames(.ls)[-nrow(.ls)],
>> function(x) mode(eval(as.symbol(x))))),
>> + "-------")
>> + .ls
>> + }
>>> my.ls()
>> Size Mode
>> .my.env 28 environment
>> .Random.seed 2,528 numeric
>> .required 72 character
>> my.ls 6,712 function
>> **Total 9,340 -------
>>
>>
>> On Tue, Jan 13, 2009 at 9:53 AM, Gundala Viswanath <gundalav at gmail.com> wrote:
>>> Dear all,
>>>
>>> Is there a way we can find the total object.size of
>>> all the objects in our R script?
>>>
>>> The reason we want to do this because we want to know
>>> how much memory does our R script require overall.
>>>
>>> Rprofmem(), doesn't seem to do it.
>>>
>>> and Unix 'top' command is dynamic and
>>> it doesn't give the exact byte size.
>>>
>>> - Gundala Viswanath
>>> Jakarta - Indonesia
>>>
>>> ______________________________________________
>>> R-help at 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.
>>>
>>
>>
>>
>> --
>> Jim Holtman
>> Cincinnati, OH
>> +1 513 646 9390
>>
>> What is the problem that you are trying to solve?
>>
>
> ______________________________________________
> R-help at 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.
>
More information about the R-help
mailing list