rstudio / rmarkdown-cookbook

R Markdown Cookbook. A range of tips and tricks to make better use of R Markdown.
https://bookdown.org/yihui/rmarkdown-cookbook/
578 stars 224 forks source link

Advanced tips : How to 'Rmd -> R files' ? knitr::purl #9

Closed cderv closed 4 years ago

cderv commented 6 years ago

I always found that this is a hidden gem. I discovered it a long time ago in @yihui's blog post about a package with literate programming.

I would find it useful in the cookbook to talk about how to extract R code for a Rmd file using knitr::purl or knitr::knitr(..., tangle = TRUE), with the use of the chunk option purl = FALSE to exclude some chunks.

It could also be mentioned in the hook part because there is an hook_purl() hook. See help file

I think it is a powerful option worth mentionning.

Related knitr example

cderv commented 4 years ago

There is now mention of knitr::purl with 080653dacf35a9e402e6db3b7a06653f60206ec7

We can also mention hook_purl()

haozhu233 commented 4 years ago

https://stackoverflow.com/questions/54796421/rmarkdown-knitrpurl-on-python-code-chunk

Might be an interesting extension

cderv commented 4 years ago

This is covered here https://bookdown.org/yihui/rmarkdown-cookbook/purl.html @yihui do you want to cover anything else on this ?

Otherwise, this can be closed.

yihui commented 4 years ago

knitr needs to support purl() for other languages, but it is hard. I think this issue could be closed, even though knitr needs to be improved.