[R] How do you capture warning messages from rstan package's stan() function, when running an R script that calls stan() on the command line?

Qian Sophia Zhang qszhang at uw.edu
Thu Aug 25 02:34:20 CEST 2016

Hi R people,

I have an R script Fit12_for_stack.R that calls rstan’s stan(). When I run the code in an interactive R session, I see warning messages from stan() about divergent transitions, but when I run the code on the command line with “Rscript Fit12_for_stack.R”, I don’t see stan() warning messages. How can I run the code on the command line and still see stan() warning messages?

>From the post How to save all console output to file in R? <http://stackoverflow.com/questions/7096989/how-to-save-all-console-output-to-file-in-r>, I tried adding

con <- file("test.log")
sink(con, append=TRUE)
sink(con, append=TRUE, type="message")
to the top of Fit12_for_stack.R, but test.log again showed output, without stan() warning messages.

Fit12_for_stack.R and a file it uses, try8.stan, are attached.


P.S. If you prefer responding via StackExchange, I also posted there: http://stackoverflow.com/questions/39134667/how-can-i-capture-warning-messages-from-rstan-r-packages-stan-function-when <http://stackoverflow.com/questions/39134667/how-can-i-capture-warning-messages-from-rstan-r-packages-stan-function-when>.

More information about the R-help mailing list