Search code examples
rknitrtexsweavechunks

Chunk with eval=FALSE still evaluates on R Sweave


I'm working on some education manuals in spanish for a course, so I'm making a Sweave document with some chunks and I'm trying to make an example of an error message. But first I need to show the souce of that error, so I'm using this code, since I don't want the code evaluating I'm using eval=FALSE:

<<eval=FALSE, error=TRUE,tidy=FALSE>>=
c(1,2 3)
#falta una coma
@

But the code is still evaluating and it's not letting me print the document, giving me this error message

(chunk 306) 5305:7: unexpected numeric constant


Solution

  • Your code is being parsed, not evaluated. If you have current versions of the knitr and evaluate, this should result in a warning in the knitr log, it won't stop the run. I'm using knitr 1.16 and evaluate 0.10.1 and things are fine. See knitr: knitting chunks with parsing errors for a bit more on this.

    (BTW, I think you're using knitr, not Sweave. They're different. Sweave can't handle this. If you really are using Sweave, switch to knitr. The switch is not hard, and brings a lot of benefits.)