Stan & R 4.2 on Windows

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.

  1. Upgrade to CmdStanR 0.5.2 or newer
install.packages("cmdstanr", repos = c("", getOption("repos")))
  1. Check the toolchain and install CmdStan
cmdstanr::check_cmdstan_toolchain(fix = TRUE)
# if you already had the latest version of CmdStan install
# cmdstanr::install_cmdstan(overwrite = TRUE) 
  1. Check that everything is running
fit <- cmdstanr::cmdstanr_example()

If you experience any issues running the example, please create an issue at 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:

  1. Remove currently installed rstan andd StanHeaders packages

If you have not installed these packages yet, proceed to step 2.

remove.packages(c("rstan", "StanHeaders"))
  1. Install from the Stan R package repository
install.packages("rstan", repos = c("", getOption("repos")))

If you experience issues running the example, please create an issue at This way you will help us improve the automatic toolchain checks and installation.


Thank you to Hamada S. Badr for addressing the rstan issue and to Tristan Mahr for helping us debug and improve the CmdStanR installation.

2 thoughts on “Stan & R 4.2 on Windows

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s