Skip to content

Instantly share code, notes, and snippets.

@vankesteren
Last active April 9, 2018 13:56
Show Gist options
  • Select an option

  • Save vankesteren/a0fc7c6f73c8abfc0f3b8e44b0fa41a8 to your computer and use it in GitHub Desktop.

Select an option

Save vankesteren/a0fc7c6f73c8abfc0f3b8e44b0fa41a8 to your computer and use it in GitHub Desktop.
Display object sizes from large to small with human-readable formatting. It's a really ugly function with a double sapply in there, but it does its job well.
object.sizes <- function(unit = "auto", all = FALSE) {
data.frame(size =
sapply(
sort(
sapply(ls(envir = parent.frame(), all.names = all), function(x) {
object.size(get(x, envir = parent.frame()))
}),
decreasing = TRUE
),
function(y) {
utils:::format.object_size(y, unit = unit)
}
)
)
}
@vankesteren

Copy link
Copy Markdown
Author

How to load & use

# load
source("https://gist.githubusercontent.com/vankesteren/a0fc7c6f73c8abfc0f3b8e44b0fa41a8/raw/objectsizes.R")

# use
object.sizes()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment