Speeding up R packages’ installation process

July 5, 2015
By

(This article was first published on Rexamine » Blog/R-bloggers, and kindly contributed to R-bloggers)

There is a time for some things, and a time for all things; a time for great things, and a time for small things — Miguel de Cervantes

Building R packages from sources may take a long time, especially if they contain a lot of C/C++/Fortran code. Long compile time might be especially frustrating if you are a package developer and you need to recompile your project very often.

Here is how long it takes to compile the stringi package on my laptop (if the ICU library is also compiled from sources):

$ time R CMD INSTALL ~/R/stringi --preclean --configure-args='--disable-pkg-config'
# real    2m6.989s

On many R installations, the build process is set up so that only one C/C++ source file is compiled at a time:

CPU and RAM Usage - before

Yet, there is a simple solution for that — we may ask GNU make to allow more than one job to be submitted at once. In order to do so, we edit the /lib64/R/etc/Renviron file (where /lib64/R/etc/ is the result to a call to the R.home() function in R) and set:

MAKE='make -j 8' # submit 8 jobs at once

instead of previously used settings.

This significantly decreases the time needed to compile stringi :

$ time R CMD INSTALL ~/R/stringi --preclean --configure-args='--disable-pkg-config'
# real    0m38.831s

CPU and RAM Usage - after

Thanks to that, we may now spend the time saved to enjoy more whomever or whatever we love. 🙂

To leave a comment for the author, please follow the link and comment on their blog: Rexamine » Blog/R-bloggers.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)