It is a bit of a challenge to get a code chunk to be printed verbatim. Yihui has written a very useful blog post: https://yihui.name/en/2017/11/knitr-verbatim-code-chunk/ that explains how to do this, but I find myself forgetting how it works, and not knowing how to search for it when I need it.
What do people think about the idea of a code chunk verbatim = TRUE?
This would parse the rmarkdown chunk for demonstration purposes.
It would mean you wouldn't need to write this in your R code:
````
```{r dev = "jpg"}`r ''`
ggplot(airquality,
aes(x = Temp,
y = Wind)) +
geom_point()
```
````
Instead, you would have the code chunk option like so:
```{r dev = "jpg", verbatim = TRUE}
ggplot(airquality,
aes(x = Temp,
y = Wind)) +
geom_point()
```
And then when knitr/rmarkdown does the magic of creating the document, it adds the appropriate magic spice of the four back ticks, plus r ''. It would feel really slick to have this verbatim feature built into the rmarkdown chunk options.
To me, it means that I don't need to spend time trying to hack my way around this issue, and more time writing code and teaching.
That said, I don't really have a clear idea on just how difficult this would be to implement inside knitr/rmarkdown - perhaps this is indeed just too difficult! I have posted an alternative suggestion to the remedy package: https://github.com/ThinkR-open/remedy/issues/61