Install CmdStan for R in Windows

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. The rebuild_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.


Read also the image in this tweet about how to install Stan and related packages after updating R to a new version (e.g. from 4.2 to 4.3). Basically, the author says that «I first completely removed R, RTools and cmdstanr, then installed R 4.3 (alpha), RTools 4.3, then make sure your path/environmental variables (on Windows) point to the correct RTools, then I installed Stan and cmdstanr (again, check path to cmdstanr in PATH variable).«

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.