Installig cmdstan version 2.36.0 and cmdstanr on the Hoffman2 Cluster

Creation date: 9/9/2025 11:29 AM    Updated: 9/9/2025 11:35 AM   cmdstan cmdstanr r
As of cmdstan version 2.36.0 there is a bug in one of the makefiles that causes the package to link to the system tbb instead of its own built one (see: https://github.com/stan-dev/cmdstan/issues/1329). 

Here is a way to patch the code from within R:


#
# remove any old installation of cmdstan if any:
#
cd ~/.cmdstan
rm -rf cmdstan-2.36.0

#
# get an interactive session with enough memory, for example:
#
qrsh -l h_data=5G -pe shared 4


#
# use a modern version of the compiler an R, for example:
#
module load gcc/10.2.0; module load R/4.5.1
module load mpfr

#
# start R and at the R prompt issue:
#
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())