knitr: knitting chunks with parsing errors

Viewed 366

Is it possible to knit chunks with parsing errors?

I want to produce a document explaining some different types of errors one can find while coding in R, but it seems that I can't knit a chunk with parsing error, even with error = TRUE.

For example, this chunk works fine and it shows the error messages:

```{r sum character, error = TRUE}
"1" + "2"
```

However, this chunk doesn't:

```{r missing parenthesis, error = TRUE}
f <- function(x){
  z <- sum(x
  #
  y <- x + 1
  return(x + y + z)
}
```

It gives the error: Error in parse(text = x, srcfile = src).

The idea here would be to show all error messages in the chunk "missing parenthesis", is this possible?

1 Answers
Related