Error: No Rstan Package when using cmdstanr for brms

I keep getting this error “Error in utils::packageVersion(“rstan”) : there is no package called ‘rstan’“ but I have installed brms, cmdstanr, and run cmdstanr::install_cmdstan(). I’ve also made sure to set the cmdstanr::set_cmdstan_path. My model refers to cmdstanr for the backend, but it looks like its still trying to pull up rstan.

library(brms)
library(cmdstanr)
brms::brm(var1 ~ var2, 
          data = df, 
          family = hurdle_gamma(), 
          backend = "cmdstanr")

Operating System: Windows
Interface Version: R 4.4.0

How do I get it to stop trying to find the rstan package version so it will run the brms model through cmdstanr?

1 Like

brms imports rstan, so rstan needs to be installed even if you use the cmdstanr backend. If you re-install brms, it should prompt you to also install rstan if indeed you don’t have a working installation. Alternatively, you can just install rstan directly.

This happens because some versions of brms still check for rstan when loading, even if you’re using cmdstanr as backend. The fix is simple: install a lightweight rstan just to satisfy the dependency check, even if you won’t use it, with install.packages(“rstan”). After that, keep calling your models with backend = “cmdstanr”. If you don’t want to install rstan, you can instead update brms to the latest CRAN or development version (remotes::install_github(“paul-buerkner/brms”)), which removes this requirement. 👊

Thanks for the reply. Trying to update to the new development version is still requiring rstan. Unfortunately, I was having issues installing rstan due to server restrictions on downloading Rtools (which resulted in errors about compiling). I will see if I can get new permissions to get Rtools and then rstan.