Skip to content

Installing RStan from source on Windows

seantalts edited this page Nov 15, 2018 · 3 revisions

In most cases, this page is not necessary. It is only necessary if you need to install RStan from source, which requires some additional configuration to the C++ toolchain provided by Rtools.

Download and Install Rtools

Download Rtools35.exe (even if you are using R 3.4.x) from If you have a previous version of Rtools installed, you should uninstall it first. We recommend that you accept all the default options as illustrated by the following screenshots. Note that it is NOT necessary to change the path anymore.

  1. Choose a language.

We recommend English since that is what the screenshots below are in

  1. Scroll through this information,

  1. Choose a directory.

We recommend accepting the default C:\Rtools (note capitalization)

  1. Select option. We recommend accepting the default

"Tools for building R packages from source"

  1. Do not add rtools to system PATH but do save the version information in the registry.

  1. Verify your selections and click Install.

You will have to wait a few minutes for it to finish.


The code below should work to create or edit a personal Makevars file programmatically from R:

dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, "")
if (!file.exists(M)) file.create(M)
cat("\nCXX14FLAGS=-O3 -march=native",
    "CXX14 = g++ -m$(WIN) -std=c++1y",
    "CXX11FLAGS=-O3 -march=native",
    file = M, sep = "\n", append = TRUE)

Be advised that setting the optimization level to 3 (CXX1*FLAGS=-O3) may prevent some other R packages from installing from source if they are only tested with the default optimization level of 2.

Installing RStan from source

You are now ready to install RStan from source. Execute in R

if (file.exists(".RData")) file.remove(".RData")

and then restart R and set the desired number of cores to use during installation

Sys.setenv(MAKEFLAGS = "-j4") # four cores used

Finally, either do

install.packages("rstan", type = "source")

to install the CRAN version of RStan from source or

remotes::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan", build_opts = "")

to install the development version of RStan from GitHub.

You can’t perform that action at this time.