knitr: knitting chunks with parsing errors

柔情痞子 提交于 2019-12-10 16:01:22

问题


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:


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.



来源:https://stackoverflow.com/questions/35842682/knitr-knitting-chunks-with-parsing-errors

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!