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

knitr, markdown, r

Solution

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).

Problem

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)?

Original source