How to Install rstan and brms

Published

January 8, 2024

For Mac Users

dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, "Makevars")
if (!file.exists(M)) file.create(M)
arch <- ifelse(R.version$arch == "aarch64", "arm64", "x86_64")
cat(paste("\nCXX14FLAGS += -O3 -mtune=native -arch", arch, "-ftemplate-depth-256"),
    file = M, sep = "\n", append = FALSE)
  • To install rstan, in the R console
    1. Remove all old rstan files, if they exist
remove.packages("rstan")
if (file.exists(".RData")) file.remove(".RData")
  1. Restart R
  2. Install StanHeaders and rstan
install.packages("StanHeaders", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
remove.packages("rstan")
if (file.exists(".RData")) file.remove(".RData")

install.packages("StanHeaders", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("brms")

You’re all set!

For Windows Users

remove.packages("rstan")
if (file.exists(".RData")) file.remove(".RData")
  1. Restart R
  2. Install StanHeaders and rstan
install.packages("StanHeaders", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
remove.packages("rstan")
if (file.exists(".RData")) file.remove(".RData")

install.packages("StanHeaders", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("brms")

You’re all set!