stevec
stevec

Reputation: 52977

Ignore all errors occurring when knitting R markdown (Rmd) file?

I know how to ignore R errors when knitting, but is it possible to knit the entire markdown doc (or as much of it as possible) whilst ignoring all errors that occur whilst knitting?

For example, if a package was missing, have the doc knit anyway (as best it can).

As an example use case, when you want to quickly knit an Rmd (possible just to quickly check something), but some other issues have occurred that you know don't affect the part you're wishing to look at.

Upvotes: 2

Views: 6269

Answers (1)

niklai
niklai

Reputation: 388

You can set the document to not to stop on errors.

knitr::opts_chunk$set(
  error = TRUE, # do not interrupt in case of errors
)

This is also true for warning messages and to include the code in the knited document.

knitr::opts_chunk$set(
  warning = TRUE, # show warnings
  message = TRUE, # show messages
  error = TRUE, # do not interrupt generation in case of errors,
  echo = TRUE  # show R code
)

If you want to do it locally you can add error=TRUE to an specific chunk.

```{r error=TRUE}
# code that will fail.
```

Upvotes: 3

Related Questions