Skip to content
Prev 309005 / 398503 Next

problem in finding sizes of objects using a for loop

Here is a function I use to get the size of objects:

Here is an example output:
Size     Mode
allStores       7,303,224     list
convertedStores         0     NULL
f.createCluster    40,508 function
x                  41,672     list
**Total         7,385,404  -------




my.ls <- function (pos = 1, sorted = FALSE, envir = as.environment(pos))
{
    .result <- sapply(ls(envir = envir, all.names = TRUE),
function(..x) object.size(eval(as.symbol(..x),
        envir = envir)))
    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),
        envir = envir)))), "-------")
    .ls
}
On Thu, Oct 25, 2012 at 2:24 AM, Purna chander <chanderbio at gmail.com> wrote: