yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.37k stars 874 forks source link

Include `knit_fail()` function to signal document failure (but not rendering failure) #2224

Open rich-iannone opened 1 year ago

rich-iannone commented 1 year ago

For deployment purposes (e.g., Connect), it would be good to have a function like knit_fail(reason) to allow for a document-level failures. One scenario might be an .Rmd file deployed as data validation checkpoint where if a particular validation failed, knit_fail() could be invoked to cause failure at the very end. Then Connect could make use of the reason text and react accordingly (e.g., cancel deploy).

One might use stop() for this type of thing but it would be better not to use that since (1) the document wouldn't be rendered and, (2) it would be useful for the user to inspect the rendered document and learn was caused the failure.

Part of https://github.com/yihui/knitr/issues/2230.

cderv commented 1 year ago

For reference, we have already a knit_exit() function that allows to stop rendering in the middle of the document. https://bookdown.org/yihui/rmarkdown-cookbook/knit-exit.html

There is no reason associated though - Don't know if tweaking this existing function would be enough for the use case shared.

rich-iannone commented 1 year ago

Will talk to Hadley about two alternatives: (1) SimpleError, and (2) knit.exit().