Last active
February 12, 2019 21:56
-
-
Save tylerlittlefield/7c0946ca72f01e30c9f1485a6daf9793 to your computer and use it in GitHub Desktop.
Check the size of an R package or project
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
# 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