Created
December 10, 2020 18:15
-
-
Save danlewer/517442d9cd5e10741561542ee87f617e to your computer and use it in GitHub Desktop.
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
objectSizeTable <- function(unit = 1e6, env = .GlobalEnv, top = 10, totals = T) { # 1e6 approximates Mb (1e9 for Gb) | |
o <- ls(envir = env) | |
y <- data.frame(object = o, size = sapply(o, function(x) object.size(get(x, envir = env)))) | |
y$size <- y$size / unit | |
y <- y[order(y$size, decreasing = T),] | |
if (totals) {y <- rbind(data.frame(object = c('total', 'other_environments'), size = c(sum(y$size), memory.size() - sum(y$size))), y)} | |
rownames(y) <- NULL | |
if (is.na(top)) return(y) else return(y[seq_len(top + (2 * totals)),]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment