R 4.0 has released, and you are wanting to use rstan. Your models no longer run, you are getting cryptic error messages, and want to post here about it.
With R4.0, and the latest compiler configuration, you must configure rstan differently. Configurations from previous versions are breaking under R 4.0. Try these things first, as they generally solve any problems I have seen others report, and problems I have observed under OSX Mojave, Catalina, and Windows 10.
Summary
R 4.0 does not require manual configuration of compiler paths. However, previous R versions may have, and those configurations are breaking rstan on R 4.0. These instructions simply remove those configurations. Most problems I have seen so far about rstan on R 4.0, from both Windows and osx users, stem from these configuration files. Files affected: Makevars
, Makevars.win
, .Rprofile
, .Renviron
. These should not be setting compiler, include, or other paths unless you know what you are doing. Compiler optimization options are fine, and options that do not affect compiler paths are fine.
This is intended for those who used rstan before 4.0, and updated to 4.0
Windows 10
- Uninstall any previous Rtools versions (e.g., Rtools35).
- Move, delete, or rename:
- Documents/.Renviron
- Documents/.R/Makevars.win
- Documents/.Rprofile
- This will remove any previous configurations from the equation altogether.
- Install Rtools 40. Do not modify the default installation options.
- If you have not already, run this in R:
writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")
You should now have only a Documents/.Renviron file.
Try compiling and running a Stan model. At this point, it should compile.
Rstan for Windows on R 4.0, with Rtools40, does not require Makevars.win to function. It does not require any compiler path, bin path (e.g., BINPREF), or include path defined.
If there are any compiler optimizations you wish to use, you can safely add it to Makevars.win. If you had custom functions or options in .Rprofile, you may return these to the file. Just ensure you are not modifying any paths related to compilation.
You may wish to add the following line to Documents/.R/Makevars.win for optimization:
CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function
OSX (Mojave, Catalina)
- Uninstall r-macos-rtools ; it is now unneeded.
- Undo the configurations made by macos-rtools:
- Open spotlight, and launch terminal.
cd ~
mv .Renviron .Renviron.bak
(this renames .Renviron, so R does not use it)cd .R
mv Makevars Makevars.bak
(this renames Makevars)
- You should have xtools installed already. If not, open terminal and run
xcode-select --install
and follow the prompts.
Open R, and compile/run a Stan model. It should now compile fine.
Like with Windows, rstan on R 4.0 does not require Makevars at all (at least, in all my testing).
At this point, you may want to add in compiler optimizations, such as CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function
to your ~/.R/Makevars
file.
Any other customizations you had in Renviron or Makevars can be returned to them as long as they do not specify directories. You do not need to specify includes, library, or compiler paths on R 4.0 with Xcode in order for rstan to function.
Edit: If you are on OSX and using Rstudio, you may have a crash when using multiple cores
This is not an rstan problem, but an Rstudio problem. See the fix here: