install.packages("remotes")
remotes::install_github("stan-dev/cmdstanr")
library(cmdstanr)
version <- "2.36.0"
cmdstan_dir <- "~/.cmdstan/cmdstan-2.36.0"
url <- paste0("https://github.com/stan-dev/cmdstan/releases/download/v", version, "/cmdstan-", version, ".tar.gz")
dest <- tempfile(fileext = ".tar.gz")
download.file(url, destfile = dest)
untar(dest, exdir = dirname(cmdstan_dir))
compiler_flags_path <- file.path(cmdstan_dir, "stan", "lib", "stan_math", "make", "compiler_flags")
lines <- lines[!grepl("^LDLIBS_TBB\\s*\\?=", lines)]
writeLines(lines, compiler_flags_path)
cmd <- sprintf("make build -C %s", shQuote(cmdstan_dir))
system(cmd)
set_cmdstan_path(cmdstan_dir)
#
# build the example to confirm it works:
#
bernoulli_stan <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
mod <- cmdstan_model(bernoulli_stan)
fit <- mod$sample(data = list(N = 10, y = c(0, 1, 0, 0, 0, 1, 0, 1, 0, 1)))
print(fit$summary())