@@ -90,6 +90,35 @@ test_that("draws() method returns draws_array (reading csv works)", {
9090 expect_equal(posterior :: variables(draws_beta_alpha ), c(" beta[1]" , " beta[2]" , " beta[3]" , " alpha" ))
9191})
9292
93+ test_that(" draws() errors with quarto cache guidance for fits created with temp output" , {
94+ # https://github.com/stan-dev/cmdstanr/issues/1012
95+ # https://github.com/stan-dev/cmdstanr/pull/1176
96+
97+ fit <- testing_fit(" logistic" , method = " sample" , seed = 123 , chains = 1 )
98+ csv_files <- fit $ output_files()
99+
100+ # Simulate a later cached re-render: the fit object still points to the temp
101+ # output files, which don't exist anymore
102+ unlink(csv_files , force = TRUE )
103+ withr :: local_options(list (
104+ # Even if cmdstanr_output_dir is now set to a non-temp directory,
105+ # it was not set when the fit was created so we should still get the error message
106+ # that mentions quarto caching
107+ cmdstanr_output_dir = test_path(" resources" ),
108+ knitr.in.progress = TRUE
109+ ))
110+
111+ expect_error(
112+ fit $ draws(),
113+ paste0(
114+ " Assertion on 'files' failed: File does not exist: '" , csv_files [[1 ]], " '.\n " ,
115+ " If this error happened when using Quarto or Rmarkdown caching,\n " ,
116+ " see `cmdstanr_output_dir` in `?cmdstanr_global_options`"
117+ ),
118+ fixed = TRUE
119+ )
120+ })
121+
93122test_that(" inv_metric() method works after mcmc" , {
94123 x <- fit_mcmc_1 $ inv_metric()
95124 expect_length(x , fit_mcmc_1 $ num_chains())
0 commit comments