yihui / knitr

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

Support `.qmd` in `purl()` (and `knit()`) #2208

Closed cderv closed 1 year ago

cderv commented 1 year ago

Closes #2165

knitr::purl("doc.qmd") will now works and conserve in-chunk YAML options comment.

Example

#| label: test-a
#| eval: true
1+1
strsplit('hello world', ' ')

#| label: test-b
#| fig.width: 10.0
#| fig.height: 7.0
if (FALSE) plot(1:10)

#| label: test-c
#| eval: false
## paste(letters, collapse = '|')
## if (1 == 1) {
##   'Awesome!'
## }

Choices is to kept the in-chunk special comment as-is, meaning the output will be a bit different than when purling a Rmd file. I hesitated to had at least the label maybe in ## label -------------, but I figured it would transformed to much from the input and keeping the YAML line intact seems best.

To make this works, knitr need to know when we are in "quarto-like" mode meaning we will have the params$yaml.code available. I adapted from existing code by explicitly checking on Quarto through the extension of input file.

On the bonus side, I added a commit to support knit("doc.qmd") so that it produces a .md file and not a .txt file as of now. markdown mode was already known by detect_pattern() for .qmd file.

cderv commented 1 year ago

I am waiting on the test, and it should be all good. It seems Github has some issues with dependencies installation.

thanks for the review !