So I would like to capture, process and relay the warning messages that happen during model fitting. I must be missing something basic as I was not able to do this. I can do this in cmdstanr
, but I want to fully support rstan
in the SBC package.
e.g. when running:
library(rstan)
model_code <- "
parameters {
real mu;
}
model {
mu ~ lognormal(0,5);
}"
m <- stan_model(model_code = model_code)
sampling(m, chains = 4, cores = 1)
I get something like:
Chain 2: Rejecting initial value:
Chain 2: Error evaluating the log probability at the initial value.
Chain 2: Exception: lognormal_lpdf: Random variable is -0.825686, but must be nonnegative! (in 'string', line 5, column 2 to column 22)
.... (lots of ther stuff)
But when running
sampling(m, chains = 4, cores = 4)
the messages only ever appear in the Viewer pane of Rstudio. I figured out I can disable the viewer pane by calling Sys.setenv("RSTUDIO" = "0")
before sampling (which is less than ideal, but I can live with this), however, even after disabling the viewer, the progress + warning messages are not shown anywhere…
I am using rstan 2.26.3
Maybe @jonah would know?