Rstan won't compile with R3.6

If your question relates to installation please provide the following information:

  • Operating System
  • RStan Version
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
  • Output of devtools::session_info("rstan")

If you are reporting a bug (thank you!) please use the issue tracker (github.com/stan-dev/rstan/issues) instead of the forums.

Hi, Iā€™ve used rstan for 4 years successfully under Windows 7. I say this so you wonā€™t think I am a novice in the use of this great tool. But I also know when I am over my head :-). I am a statistician, not a software professional.

Today I upgraded RStudio to 1.2.1335 and R to 3.6.0 and rstan to 2.18.2.
Now I canā€™t compile even the 8 schools example. Iā€™m screwed. I get the following ugly message:
ā€œError in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! Error in .shlib_internal(commandArgs(TRUE)) :
C++14 standard requested but CXX14 is not defined
Calls: ā†’ .shlib_internal
Execution halted
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ā€˜C:/PROGRA~1/R/R-36~1.0/bin/x64/R CMD SHLIB file306050bf18a9.cpp 2> file306050bf18a9.cpp.err.txtā€™ had status 1
Error in sink(type = ā€œoutputā€) : invalid connectionā€

Iā€™ve sought help on line. I see others have a similar problem and seem to have solved it by modifying a makevars.win file. I have no idea what they are doing. Iā€™m afraid this solution is way out of my league. Any advice? Below is the output of the 2 requested codes. Means nothing to me. Please help. Thanks!! Dave

writeLines(readLines(file.path(Sys.getenv(ā€œHOMEā€), ā€œ.R/Makevarsā€)))
Error in file(con, ā€œrā€) : cannot open the connection
In addition: Warning message:
In file(con, ā€œrā€) :
cannot open file ā€˜C:/Users/Dave/Documents/.R/Makevarsā€™: No such file or directory
devtools::session_info(ā€œrstanā€)
Error in loadNamespace(name) : there is no package called ā€˜devtoolsā€™

I think this has been resolved here: https://github.com/stan-dev/rstan/issues/633#issuecomment-491558135

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

Jeffrey,

Thank you!!! (also thank you to Randall Pruim for his insight and suggestions)

I had already completed your steps 1 and 2, so I just performed the creation of the Makevars.win file using exactly the 3 lines (and only those 3 lines) you recommended. This was easy to do as this file can be created and edited using Windows Notepad text editor and saved in ā€œC:\Users\Dave\Documents.Rā€ (my user directory). Of course I have absolutely no clue what these 3 lines mean.

I did not perform your steps 4 and 5. From the ā€œgetting startedā€ page https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started , I get the feeling that with RStudio 1.2.1335 (which I use) Rtools are not needed (am I wrong?).

Now the 8 school example compiles and runs!! J Iā€™m now a Stan forum fan.

FYIā€¦ here is what I know about my system:

HP ZBook 15u G2 IntelĀ® Coreā„¢ i7-5500U CPU @ 2.40GHz

64-bit OS

Windows 7 Professional Service Pack 1

RStudio Version 1.2.1335

R version 3.6.0

Rstan version 2.18.2

Best regards,

Dave

I followed your directions. Seems better, but still isnā€™t working: new error message.

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! Warning message:
In system(cmd) : ā€˜makeā€™ not found
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ā€˜C:/PROGRA~1/R/R-3.6.0/bin/x64/R CMD SHLIB file5b645d63a2a.cpp 2> file5b645d63a2a.cpp.err.txtā€™ had status 1
Error in sink(type = ā€œoutputā€) : invalid connection