This took me some time to make it work, so I’ll write the details here for the benefit of my future self and anyone else facing similar issues.
To run R in the Apocrita cluster (which runs CentOS 7) first load the modules
module load R module load gcc
(gcc is required to compile the packages from source.)
Before starting you should make sure that you don’t have any previous installation of RStan in your system. From an R terminal, type:
remove.packages("rstan") remove.packages("StanHeaders") if (file.exists(".RData")) file.remove(".RData")
One problem that I had initially was (I think) due to the fact that Rcpp and rstan had been installed with different compiler or compilation flags. Thanks to the IT support at Queen Mary University, the correct C++ toolchain configuration that made the trick for me is the following:
CXX14 = g++ -std=c++1y CXX14FLAGS = -O3 -Wno-unused-variable -Wno-unused-function -fPIC
To write the correct configuration in the
~/.R/Makevars file from an R terminal:
dotR <- file.path(Sys.getenv("HOME"), ".R") if (!file.exists(dotR)) dir.create(dotR) M <- file.path(dotR, "Makevars") if (!file.exists(M)) file.create(M) cat("\nCXX14 = g++ -std=c++1y", "CXX14FLAGS = -O3 -Wno-unused-variable -Wno-unused-function -fPIC", file = M, sep = "\n", append = TRUE)
Finally, install RStan:
Sys.setenv(MAKEFLAGS = "-j4") # four cores used for building install install.packages("rstan", type = "source")
Note that in my case it worked correctly without requiring to run the instructions specific for CentOS 7.0 indicated at rstan installation page.
Another thing that I did, although I am not sure it is strictly necessary, was to install RStan on a new R library, that is in a directory that contained only packages necessary to run RStan.