I'm trying to convert a pretty critical database interface script to R markdown for documentation purposes, with the intent of then tangling that file to produce the R code that goes into my crontab. I've found however that if I set eval=T then kniting the file runs the code (which I don't want to happen unexpectedly) and if I set eval=F then tangling the file produces all commented code.
Is there a safe way to produce a file that tangles into runnable code without running the risk of execution? I suppose I could find/replace eval=F every time but that seems inelegant.
Revisiting this question years later, there is a much easier answer:
You can combine the code chunk arguments eval=FALSE, comment=NA to:
knit(), andpurl()This argument is described on the page: https://yihui.org/knitr/options/ in a section called "Code Decoration".
Perhaps this is already described in another post somewhere, but I just spent hours trying to figure out how to do this with "hooks" and knitr source code before finding the answer that I knew must be out there. Hope this makes it easier for the next person!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With