yihui / knitr

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

Add init and finish hook for `knitr::knit()` #2223

Open cderv opened 1 year ago

cderv commented 1 year ago

This idea came up with discussion for https://github.com/yihui/knitr/issues/2219 in https://github.com/r-lib/rlang/issues/1551

At first it was something that could have been needed as rlang needed to set thinks at start of knitting, and reset after knitting. Solution was done another way (https://github.com/r-lib/rlang/pull/1557/commits/6b3cbe92de5cf1bc6bf9f6c6acfbc6e022454c54)

However, the idea is interesting to have those hooks available for other to extend knitr. So leaving this issue open to keep track of the idea, but we can wait for another real use case.

yihui commented 1 year ago

I'm okay with adding these hooks. https://github.com/yihui/knitr/blob/a007b376174ea080ae8ab4668509535dea30a5f5/R/output.R#L254