Traceplot does not work when called from within a function

I am doing some simulation work where in each simulation iteration I call pre-compiled Stan models (using the rstan sampling function). When I go to a new factor-level combination of my simulation inputs I like to look carefully at the MCMC diagnortics for 30 or so trials. In my simulation R function I inserted calls to pairs and traceplot just after the call to sampling. The pairs plot come out fine, but not the traceplot results. Traceplot works fine when I save a stanfit object and call traceplot from the R command line. What am I doing wrong?

I am running on Windows 10 using using R 3.6.3 and rstan 2.21.2.

1 Like

Hi, this is possibly more of a general R thing. R does by default print return values of functions evaluated in console. So often what you need to do to see plots from within a function is either a) return the plot or b) call print(your_plot)

Good luck with your work!

1 Like

Thanks very much. print(your_plot) did the trick.