As you may be aware, R 4.2.0 has just been released. For Stan users on Windows this is notable because, along with other new features, the release is accompanied with a new version of Rtools. Rtools is a toolchain bundle used for building packages from source and more importantly for Stan users, used to build Stan models into object files or executables. There are no changes for users on MacOS and Linux.
Whenever a new toolchain is introduced, it is very likely that there will be hiccups and problems. Although the Stan development team has a testing infrastructure to cover some of the possible scenarios, it is unfortunately impossible to cover all of them. We will try our best to update the recommended installation instructions as more information becomes available.
Our recommendation is that, if possible, Stan users on Windows hold off from upgrading to R 4.2. We suggest waiting a bit, so more information on the new toolchain becomes available and our developers gains some more insight to help you with any potential issues.
If you require or want to use the new features of R 4.2 or just like to live on the more adventures side, below are some additional details on using CmdStanR with R 4.2 on Windows.
CmdStanR with R 4.2 on Windows
Rtools42 required upgrading our automatic toolchain checks and install in CmdStanR so you do not have to deal with anything outside of R. Run these steps to make sure you will be able to compile and run your models with R 4.2 on Windows.
- Upgrade to CmdStanR 0.5.2 or newer
install.packages("cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
- Check the toolchain and install CmdStan
cmdstanr::check_cmdstan_toolchain(fix = TRUE)
cmdstanr::install_cmdstan()
# if you already had the latest version of CmdStan install
# cmdstanr::install_cmdstan(overwrite = TRUE)
- Check that everything is running
fit <- cmdstanr::cmdstanr_example()
fit
If you experience any issues running the example, please create an issue at https://github.com/stan-dev/cmdstanr/issues. This way you will help us improve the automatic toolchain checks and installation.
Rstan with R 4.2 on Windows
The current CRAN Rstan (version 2.21.5) does not work with R 4.2 on Windows. While the package will install successfully, we have yet to find a way to compile Stan models with the CRAN version.
The Rstan hosted on our R-package repository (version 2.26.11) includes the necessary fixes and supports R 4.2 on Windows as well. To install that version run the following steps:
- Remove currently installed rstan andd StanHeaders packages
If you have not installed these packages yet, proceed to step 2.
remove.packages(c("rstan", "StanHeaders"))
- Install from the Stan R package repository
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
If you experience issues running the example, please create an issue at https://github.com/stan-dev/rstan/issues. This way you will help us improve the automatic toolchain checks and installation.
Acknowledgments
Thank you to Hamada S. Badr for addressing the rstan issue and to Tristan Mahr for helping us debug and improve the CmdStanR installation.
Hi, is this still recommended? Thanks!
LikeLike
Yes.
LikeLike