Skip to content

Instantly share code, notes, and snippets.

@tylerlittlefield
Last active February 12, 2019 21:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerlittlefield/7c0946ca72f01e30c9f1485a6daf9793 to your computer and use it in GitHub Desktop.
Save tylerlittlefield/7c0946ca72f01e30c9f1485a6daf9793 to your computer and use it in GitHub Desktop.
Check the size of an R package or project
# Check Package Size
#
# Thanks to Alan Dipert for the help with this one.
#
# This function is used to calculate size of package and report size in
# README.md
pkg_size <- function(package) {
root <- find.package(package)
rel_paths <- list.files(root, all.files = TRUE, recursive = TRUE)
abs_paths <- file.path(root, rel_paths)
paste0(round(sum(file.info(abs_paths)$size) / 1e6, 2), " MB")
}
# OLD, don't use
# pkg_size <- function() {
# files <- list.files(".", all.files = TRUE, recursive = TRUE)
# files_info <- file.info(files)
# pkg_size_bytes <- round(sum(files_info$size) / 1e6, 2)
# pkg_size_mb <- paste0(pkg_size_bytes, " MB")
# return(pkg_size_mb)
# }
#
# pkg_size()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment