Parallel Installation of R Packages
Installing R packages on Linux is time consuming if the packages include compiled code – which is the case for a lot of contemporary packages.
To speed things up we can use the argument
install.packages("here", Ncpus = 4)
The optional arguments for
remotes::install_* are passed on to
Ncpus can be used here as well.
detectCores from the standard library package
parallel can detect the number of available (logical) cores.
In my Docker images with R I now use
Ncpus and experience a great speedup.
The number used in
Ncpus can be set with a build argument called
NCORES is specified it is available as an environment variable with a value during the build.
If it is not specified the environment variable is an empty string.
I use this behavior to set a default number if
NCORES is not specified:
Sys.getenv("NCORES", unset = parallel::detectCores())