Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

knitr: knitting chunks with parsing errors

Tags:

r

knitr

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?

like image 965
Carlos Cinelli Avatar asked Mar 14 '23 00:03

Carlos Cinelli


1 Answers

This has become possible since the evaluate package >= v0.8.4 (which is expected to be v0.9 on CRAN in the future). For now, you can install evaluate from Github.

like image 126
Yihui Xie Avatar answered Mar 15 '23 13:03

Yihui Xie