Installing CmdStan with Anaconda

Anaconda download screenshot

Go to the Anaconda download page and download the Anaconda installer, clicking on the Download link as shown in the screenshot.

Run the installer, making sure to select install Anaconda for “just me” instead of “all users”. This will not require admin rights. The installer will take a long time to run but it will install Anaconda on your machine.

Anaconda Prompt screenshot

Next, open the Anaconda Prompt (you can find this by typing “Anaconda Prompt” in your search bar and run the following code to install CmdStan:

conda install conda-forge::cmdstan

Unfortunately because we are installing CmdStan in a nonstandard way, it is not going to be automatically detected by cmdstanr when R starts up. We need to add a startup script that will run every time RStudio starts, that will tell R where to find the CmdStan software on your machine. To do this, you’ll need to create a text file in your home directory. The home directory should be C:\Users\YOURUSERNAME\Documents. Put this line in the text file, replacing YOURUSERNAME with your user name (for example, my user name on my PC is Quentin.Read).

suppressMessages(cmdstanr::set_cmdstan_path('C:/Users/YOURUSERNAME/AppData/Local/anaconda3/Library/bin/cmdstan'))

Save the text file as .Rprofile. Note it should not have an extension like .txt! Now when you start R, CmdStanR will always set the path to where CmdStan is installed.

All of the above only needs to be done once.