I want to include error messages in an R markdown pdf report. This works well:
---
output: pdf_document
---
This will be knitted and show the error message in the pdf.
```{r, error = TRUE}
stopifnot(2 == 3)
```
However, if I try the same approach with an error that comes from testthat
, my document does not knit anymore.
---
output: pdf_document
---
This will not knit
```{r, error = TRUE}
library(testthat)
expect_equal(2, 3)
```
Why is that? And what can I do to include error messages from testthat
's expect_something
functions without wrapping them up in a test?
I think this must be possible since Hadley Wickham includes many error messages in his book R packages that come directly from expect_something
-functions.
This is related, but not answered in Include errors in R markdown package vignette and How to skip error checking at Rmarkdown compiling?