[R] Summary of Total Object.Size in R Script

jim holtman jholtman at gmail.com
Tue Jan 13 16:17:52 CET 2009


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?




More information about the R-help mailing list