Cannot install rstan on a Linux supercomputer

Start with a short summary of your inquiry.
Hi everyone, I’m trying to run my rstan program on a supercomputer provided by my university. The supercomputer is under Linux operation system. However, when I install rstan in Rstudio, I encounter the following Error messages. Does anyone have any idea about solving this issue? Thank you very much!

Error: compilation failed for package 'V8'
* removing '/home/nrkettle/R/x86_64-pc-linux-gnu-library/4.2/V8'
Error: C++14 standard requested but CXX14 is not defined
* removing '/home/nrkettle/R/x86_64-pc-linux-gnu-library/4.2/StanHeaders'
* restoring previous '/home/nrkettle/R/x86_64-pc-linux-gnu-library/4.2/StanHeaders'
Error: compilation failed for package 'V8'
* removing '/home/nrkettle/R/x86_64-pc-linux-gnu-library/4.2/V8'
Error: dependency 'V8' is not available for package 'rstan'
* removing  '/home/nrkettle/R/x86_64-pc-linux-gnu-library/4.2/V8'

What C++ compiler and version do you have on the system?

Hi Andrew,

Please bear with me. My knowledge with C++ is zero… But I get it correct, I think the C++ compiler seems to be ‘gcc’ and the version is 9.

No worries! That compiler version should be more than fine, so it’s likely just an issue of R not knowing which one to use for different standards of c++.

To fix this, you just need to update the Makevars file, which is used to provide additional arguments/flags to R when compiling code. To update this from R, you just need to run:

# Create ~/.R directory if not already present
dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)

# Create Makevars file if not already present
M <- file.path(dotR, "Makevars")
if (!file.exists(M)) file.create(M)

# Specify compiler to use for C++14 code
cat("\n CXX14 = g++",
    file = M, sep = "\n", append = TRUE)

# Request maximum optimisation when compiling (gives faster Stan models)
cat("\n CXX14FLAGS += -O3  -mtune=native -march=native",
    file = M, sep = "\n", append = TRUE)

Then restart your R session and try the installation again