How can I minimize the size of the installation of a R package

Viewed 192

At my workplace we are installing a lot of libraries for different versions of R. Size required is quickly going up. What can I do to minimise each installation as much as possible? I know about --no-docs and I require --with-keep.source

EDIT: Here is a quick study on my setup

I copied my library in /tmp/library

library(fs)                                                                             
library(data.table)                                                                     
library(stringr)
lib_dir <- "/tmp/library"                                                               
pkgs <- dir_ls(lib_dir)
dirs <- dir_info(pkgs, recurse = TRUE)[,1:3]                                            
setDT(dirs)
dirs <- dirs[type != "directory"]

# ==> We can see files at the root of each library take 12M in aggreagte <==
dirs[depth == 4, .(size = sum(size))]
#    size
# 1:  12M

dirs[, depth := str_count(path, "/")]
dirs[, pkg := file.path(lib_dir, str_match(path, sprintf("%s/(.*?)/.*", lib_dir))[,2L])]
dirs[depth > 4L, pkg_dir := str_match(path, sprintf("%s/(.*?)/.*", pkg))[,2L]]

# ==> The worst offenders are indeed libs, and lib is also large <==
dirs[depth > 4, .(size = sum(size)), pkg_dir][order(-size)][1:10]
#     pkg_dir    size
#  1:    libs 610.77M
#  2: include 144.18M
#  3:     doc 140.93M
#  4:     lib 104.58M
#  5:       R  91.31M
#  6:    help  61.78M
#  7:    html  51.02M
#  8:    data   25.9M
#  9:    java  11.74M
# 10:     www   8.38M

I then ran strip --strip-debug on libs and lib to reach the following

dirs[depth > 4, .(size = sum(size)), pkg_dir][order(-size)][1:10]
#         pkg_dir    size
#  1:     include 144.18M
#  2:         doc 140.93M
#  3:        libs  95.24M
#  4:           R  91.31M
#  5:        help  61.78M
#  6:        html  51.02M
#  7:        data   25.9M
#  8:        java  11.74M
#  9:         www   8.38M
# 10: htmlwidgets   8.24M

From the above example I have the following questions: docs seem to hold vignettes that I can access doing browseVignettes() I do not need this but I still require help("stuff") to work.

  • Can I achieve this maybe using --no-docs or --no-help (I tried but running R CMD INSTALL --no-docs --no-html xtable still generates pdfs and html files)?
  • Is there something else I can save without losing basic functionality ?
1 Answers

Dirk EddelBuettel wrote two blog posts in 2017 that are hard to summarize here. R packages are big but it does not come from the documentation or the source code. It comes from the fact that binaries are compiled with debugging symbols. The idea is to compile the packages yourself with more specific options to get rid of useless stuff in binaries. The gain is very significant for packages with compiled code (4-5 times less space)

Related