Skip to content

Instantly share code, notes, and snippets.

@tyluRp tyluRp/pkg_size.R
Last active Feb 12, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.