Assuming that Rtools is already installed, these are the steps to install cmdstanr from RStudio in Windows 10:
install.packages("devtools")
devtools::install_github("stan-dev/cmdstanr")
library(cmdstanr)
This is cmdstanr version 0.5.3 – CmdStanR documentation and vignettes: mc-stan.org/cmdstanr – CmdStan path: C:/Users/tonis/Documents/.cmdstan/cmdstan-2.30.0 – CmdStan version: 2.30.0 A newer version of CmdStan is available. See ?install_cmdstan() to install it. To disable this check set option or environment variable CMDSTANR_NO_VER_CHECK=TRUE.
check_cmdstan_toolchain()
Error: Rtools42 installation found but the toolchain was not installed. Run cmdstanr::check_cmdstan_toolchain(fix = TRUE) to fix the issue. cmdstanr::check_cmdstan_toolchain(fix = TRUE)
Installing mingw32-make and g++ with Rtools42. The C++ toolchain required for CmdStan is setup properly!
check_cmdstan_toolchain()
The C++ toolchain required for CmdStan is setup properly!
install_cmdstan()
# This check, download and install the latest release (it takes long!)
[…]
* Finished installing CmdStan to C:/Users/you/Documents/.cmdstan/cmdstan-2.31.0 CmdStan path set to: C:/Users/you/Documents/.cmdstan/cmdstan-2.31.0
«The
install_cmdstan()
function attempts to download and install the latest release of CmdStan. Installing a previous release or a new release candidate is also possible by specifying the version or release_url argument. Therebuild_cmdstan()
function cleans and rebuilds the CmdStan installation. Use this function in case of any issues when compiling models.«
From time to time it might be worth to check if a new version is available. In such case, install_cmdstan()
and rebuild_cmdstan()
will do rest.
If all goes well, you can use backend = "cmdstanr
« to fit brms models.
The main reference to this summary is the CmdStan User’s Guide.
Read also this page with some other recommendations, for example:
Instead of installing R in the standard location, C:\Program Files\R\R-x.y.z, I suggest that you use C:\R\R-x.y.z. Again, x.y.z is the current version of R. This will allow you to install packages in the main R library without running R with administrator privileges and may avoid problems that sometimes occur when there are spaces in paths.