You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Errors re-rendering quarto html with cached chunks and cmdstanr. #1012
This is because cmdstanr will use the R session temporary directory for the sampling outputs by default, when you re-render the temporary directory may have changed and so the sampling results are no longer there.
If you want to reuse the fit object across multiple runs then I'd suggest using the output_dir argument of $sample() so that the sampling results are always in an expected location:
@jgabry any chance you're familiar with quarto and caching? I wonder if there's a specific change we need to make to enable CmdStanFit objects to be cached with the draws (maybe some R6 trickery?)
@jgabry any chance you're familiar with quarto and caching? I wonder if there's a specific change we need to make to enable CmdStanFit objects to be cached with the draws (maybe some R6 trickery?)
So the issue is that the draws aren't in memory when the object is cached, right?
I think quarto relies on knitr to do the caching, and if I'm looking in the right place in knitr's source code it looks like knitr just uses base R's save function:
That's unfortunate because I was hoping we could just define a custom method for whatever function knitr was using to do the caching. But save isn't a generic function with methods so I don't think that's possible. Internally save calls functions like gzfile, xzfile, etc., and I don't think we can define custom methods for those either.
Maybe there's some other approach that I'm overlooking!
Quarto caches the fit object which has paths to the output csv files. By default the output csv files are in tmp directory which gets removed when rendering stops. Cache works if the cmdstanr_output_dir is not a temporary directory. Set cmdstanr_output_dir before creating the fit object
Activity
andrjohns commentedon Jul 19, 2024
This is because
cmdstanrwill use the R session temporary directory for the sampling outputs by default, when you re-render the temporary directory may have changed and so the sampling results are no longer there.If you want to reuse the
fitobject across multiple runs then I'd suggest using theoutput_dirargument of$sample()so that the sampling results are always in an expected location:Also, you should update your
cmdstanrpackage, the current version is 0.8.1andrjohns commentedon Jul 19, 2024
@jgabry any chance you're familiar with quarto and caching? I wonder if there's a specific change we need to make to enable
CmdStanFitobjects to be cached with the draws (maybe some R6 trickery?)jgabry commentedon Jul 19, 2024
So the issue is that the draws aren't in memory when the object is cached, right?
I think quarto relies on knitr to do the caching, and if I'm looking in the right place in knitr's source code it looks like knitr just uses base R's
savefunction:https://github.com/yihui/knitr/blob/fb1f4231d2df7b156e314686f39fc040ce807513/R/cache.R#L30
That's unfortunate because I was hoping we could just define a custom method for whatever function knitr was using to do the caching. But
saveisn't a generic function with methods so I don't think that's possible. Internallysavecalls functions likegzfile,xzfile, etc., and I don't think we can define custom methods for those either.Maybe there's some other approach that I'm overlooking!
avehtari commentedon Apr 8, 2026
Quarto caches the fit object which has paths to the output csv files. By default the output csv files are in tmp directory which gets removed when rendering stops. Cache works if the
cmdstanr_output_diris not a temporary directory. Setcmdstanr_output_dirbefore creating the fit objectjgabry commentedon Apr 8, 2026
Great, thanks @avehtari. Can we close this then?
Informative error message if temp csv files are not found during Quar…