Skip to content

Using RStan with the R 4.0 Prerelease on Windows

bgoodri edited this page Feb 4, 2020 · 1 revision

The next major version of R, namely 4.0, will likely be released in early-ish 2020 and the Windows version will use a new version of RTools that comes with version 8.x of the g++ compiler. However, it is possible today to use Stan with a prerelease of R 4.0, which is likely a better option for research that utilizes Stan than using the current version of R (3.5.x) with the version 4.9.3 of g++ that comes with RTools currently. The reasons for this statement include:

  • In version 4.9.3 of g++ used by R 3.5.x, the implementation of the C++14 standard is incomplete, which may yield subtle bugs (although we test for obvious bugs). The C++14 implementation was completed in version 5 of g++, so version 8.x has a very mature implementation of the C++14 standard (and a complete albeit less mature implementation of the C++17 standard).
  • Version 8.x of g++ is likely to generate code that executes faster, particularly on hardware that was introduced after version 4.9.0 of g++ was released in 2014
  • With version 8.x of g++, you can utilize threading, MPI, and GPUs, some of which do not work with version 4.9.3 of g++

You can install the pre-release of R version 4.0 along with corresponding RTools40 alongside an existing installation of R and RTools --- so it will not interfere with any other work you want to do in the existing R --- by going to https://cloud.r-project.org/bin/windows/testing/rtools40.html and following the instructions. The only real drawback to this approach is that it consumes a lot of disk space, and some non-Stan R packages might not be ready for the transition yet.

For more information about this effort, see Part III of https://jeroen.github.io/uros2018/ .

Start the pre-release of R 4.0 and do

install.packages(c("RcppEigen", "pkgbuild", "BH", "rstan"))
pkgbuild::has_build_tools(debug = TRUE) # will offer to install rtools40

to use Stan as normal.

If you want to change your RStudio to use the 3.6.0 pre-release of R, open RStudio and go to Tools -> Global Options and then click on the Change button in the upper right and select [64 bit] C:\Program Files\R\R-testing or similar. Then click through the OK buttons and restart RStudio. You would follow a similar process to switch back to a previous version of R.