Status on RStan, CRAN, and latest versions of Stan?

This is now supported in the nightly version of stanc3:

file.remove(system.file("stanc.js", package = "rstan"))
download.file("https://github.com/stan-dev/stanc3/releases/download/nightly/stanc.js", file.path(find.package("rstan"), "stanc.js"))

(before loading rstan… or restart the R session)

This is stored in the C++ code, generated by rstan::stanc() which is where those flags are effective. You may expose the model compile info in R and check it.

You may check the generated C++ code or expose the model compile info in rstanarm (edit the source code). But, in general, you do need to set the optimization option in ~/.Rprofile and restart the R session since the package build doesn’t respect the options or environment variables (e.g., when it’s built using R CMD). Adding the option in ~/.Rprofile will apply it globally except for no-profile sessions which is not the default.

Great!

I know it’s stored in the C++ code, but thinking of users, it would be nice to show the info a bit more easily than getting hundreds lines of C++ code and search for the string there.

I can also confirm that options(stanc.allow_optimizations = TRUE) works with brms when the backend=rstan.

1 Like

If you enable the optimization option in ~/.Rprofile and reinstall rstanarm, you’ll most likely get performance improvement too. The compilation may take longer though.

We could store the info into the objects. For now, you may use the following function:

stanc_info <- function(cppcode) {
  cppcode <- scan(what = character(), sep = "\n", quiet = TRUE, text = cppcode)
  cppcode <- cppcode[grepl("stancflags", cppcode)]
  cat(strsplit(cppcode, '"')[[1]][c(2,4)], "\n")
}

Example:

stanmodelcode <- "
data {
  int<lower=0> N;
  real y[N];
} 

parameters {
  real mu;
} 

model {
  mu ~ normal(0, 10);
  y ~ normal(mu, 1); 
} 
"

r <- stanc(model_code = stanmodelcode, model_name = "normal1")

stanc_info(r$cppcode)

On my machine, this prints the following:

stanc_version = stanc3 8fce5fb2 stancflags = --O1
1 Like