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:
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
Thanks to that, we may now spend the time saved to enjoy more whomever or whatever we love. :)
Note that MAKE is an environmental variable and can also be changed from within the current R session (
Sys.setenv) or while we start R from the Linux/Unix terminel (
MAKE="..." R – thanks to Nick Kennedy for noticing that).