Rstan won't compile with R3.6

Check out this thread: Problems configuring Makevars.win since R 3.6.0

What worked for me (on Win10) was the following:

  1. Uninstall rstan package (to be safe) by running the following command in R
remove.packages("rstan")
if (file.exists(".RData")) file.remove(".RData")
  1. Open (or create) the Makevars.win file by running the following command in R
M <- file.path(Sys.getenv("HOME"), ".R", "Makevars.win")
file.edit(M)
  1. Add the following three lines to the Makevars.win file
CXX14=$(BINPREF)g++
CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=native -mtune=native
  1. Install RTools 4.0 to the default location (C:/rtools40/)
    https://cloud.r-project.org/bin/windows/testing/rtools40.html

  2. Run the following commands in R

Sys.setenv(MAKEFLAGS = paste0("-j", parallel::detectCores()))
install.packages("pkgbuild", INSTALL_opts = "--no-multiarch")
cat("Rtools version 4.0.0", file = file.path("C:", "rtools40", "VERSION.txt"), sep = "\n")
cat("Rtools 4.0", file = file.path("C:", "rtools40", "Rtools.txt"), sep = "\n")
install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE, INSTALL_opts = "--no-multiarch")
options(mc.cores = parallel::detectCores())
rstan::rstan_options(auto_write = TRUE)

If you want to install Rtools in a non-default location, you need to update lines 4-5 above.

Good luck and please post again letting us know if this worked or not.

4 Likes