Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write markdown documents with R code that doesn't work, on purpose

Tags:

markdown

r

knitr

I'm experimenting with using Markdown to write homework problems for a course that involves some R coding. Because these are homework sets, I intentionally write code that throws errors;. Is it possible to use Markdown to display R code in the code style without evaluating it (or to trap the errors somehow)?

like image 243
Drew Steen Avatar asked Dec 09 '25 20:12

Drew Steen


1 Answers

If you're using R markdown, putting eval=FALSE in the chunk options should work. Or use try(). Or, if you're using knitr as well, I believe that the default chunk option error=FALSE doesn't actually stop the compilation when it encounters an error, but just proceeds to the next chunk (which sometimes drives me crazy).

like image 60
Ben Bolker Avatar answered Dec 12 '25 17:12

Ben Bolker