Last active
December 17, 2015 14:29
-
-
Save benmarwick/5625246 to your computer and use it in GitHub Desktop.
List data object in memory with size (in kB) and mode. From http://r.789695.n4.nabble.com/Size-of-an-object-in-workspace-tp823649p823653.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List data object in memory with size (in kB) and mode. From http://r.789695.n4.nabble.com/Size-of-an-object-in-workspace-tp823649p823653.html | |
ls.kb <- 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 (kB)" | |
.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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment