Skip to content

Informative error message if temp csv files not found by Quarto#1178

Draft
jgabry wants to merge 3 commits intomasterfrom
fix-quarto-cache-fit-tempdir-hint
Draft

Informative error message if temp csv files not found by Quarto#1178
jgabry wants to merge 3 commits intomasterfrom
fix-quarto-cache-fit-tempdir-hint

Conversation

@jgabry
Copy link
Copy Markdown
Member

@jgabry jgabry commented Apr 9, 2026

Submission Checklist

  • Run unit tests
  • Declare copyright holder and agree to license (see below)

Summary

Fixes #1012

This an alternative to #1176 that takes a different approach to giving the user an informative message when quarto fails to find the csv files.

Copyright and Licensing

Please list the copyright holder for the work you are submitting
(this will be you or your assignee, such as a university or company):
Jonah Gabry

By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses:

error = function(e) {
err_msg <- conditionMessage(e)
if (isTRUE(getOption("knitr.in.progress")) &&
isTRUE(self$runset$args$using_tempdir) &&
Copy link
Copy Markdown
Member Author

@jgabry jgabry Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do it here instead of inside read_cmdstan_csv() we can access the internal using_tempdir flag, which is more reliable than checking getOption(cmdstan_output_dir) because the option may have changed between the initial quarto caching and the later re-rendering (so it's not a 100% reliable indicator of whether the temp directory was used).

@jgabry
Copy link
Copy Markdown
Member Author

jgabry commented Apr 10, 2026

@avehtari This PR is more complicated than yours because with this strategy we need to do it for every different type of fitted model object (mcmc, mle, pathfinder, etc.). In your version we could just do it in read_cmdstan_csv(), which is much simpler but I couldn't figure out how to solve this problem without using an approach like this. I guess we could use your initial strategy of checking for evidence of tempdir in the path, but we'd need to make sure it works on Mac, windows, linux, WSL, and I wasn't sure of a reliable way to do that (but maybe there is). I would prefer to merge a simpler PR like yours, so maybe we can figure something out.

@jgabry jgabry marked this pull request as draft April 10, 2026 00:21
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.10%. Comparing base (801b2b4) to head (bd2e806).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1178      +/-   ##
==========================================
- Coverage   91.23%   91.10%   -0.14%     
==========================================
  Files          15       15              
  Lines        6070     6116      +46     
==========================================
+ Hits         5538     5572      +34     
- Misses        532      544      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@avehtari
Copy link
Copy Markdown
Member

This PR doesn't do anything for me

�[31m

processing file: quarto_test.R
�[39m1/7                  
2/7 [unnamed-chunk-1]
3/7 [mod1]           
4/7 [fit1]           
5/7 [unnamed-chunk-2]
�[31mError in `read_cmdstan_csv()`:
! Assertion on 'files' failed: File does not exist: '/tmp/RtmpNEy1UM/bioassay1-202604082047-1-769fdd.csv'.
Backtrace:
     ▆
  1. ├─base::withVisible(knit_print(x, ...))
  2. ├─knitr::knit_print(x, ...)
  3. └─knitr:::knit_print.default(x, ...)
  4.   └─knitr::normal_print(x)
  5.     ├─base::print(x)
  6.     └─R6:::print.R6(x)
  7.       └─.subset2(x, "print")(...)
  8.         └─self$summary(variables_to_print, ...)
  9.           └─self$draws(variables)
 10.             └─private$read_csv_(...)
 11.               └─cmdstanr::read_cmdstan_csv(...)
 12.                 └─cmdstanr:::assert_file_exists(files, access = "r", extension = "csv") at cmdstanr/R/csv.R:141:3
 13.                   └─checkmate::makeAssertion(files, res, .var.name, add)
 14.                     └─checkmate:::mstop(...)
�[39m�[31m
Quitting from quarto_test.R:41-45 [unnamed-chunk-2]
�[39m�[31mExecution halted
�[39m�[33mWARN: Error encountered when rendering files�[39m

@jgabry
Copy link
Copy Markdown
Member Author

jgabry commented Apr 10, 2026

Weird, it worked when I tried it. But I did make a few edits after testing it so maybe I broke it. I’ll investigate.

@jgabry
Copy link
Copy Markdown
Member Author

jgabry commented Apr 10, 2026

@avehtari Was your fitted model object created using the cmdstanr from this branch or did you already have it from before? It needs to be created using this version of cmdstanr on this branch because of the way R6 objects work

@avehtari
Copy link
Copy Markdown
Member

I did switch to this branch, rendered without cache which should then crearte fit object with this branch, and then rendered with cache

@jgabry
Copy link
Copy Markdown
Member Author

jgabry commented Apr 10, 2026

Ok interesting, I’ll try to figure it out later when I have some time. Maybe I did something wrong when testing it myself yesterday.

@avehtari
Copy link
Copy Markdown
Member

My mistake, I remembered wrong when cache gets cleared, and when I did run with cache=false and then with cache=true, the cache was still having the old version. After clearing the cache, this PR works. So this PR works only after the fit object in the cache has been created with this PR, while my PR works also if the cache has been created with earlier version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Errors re-rendering quarto html with cached chunks and cmdstanr.

3 participants