2

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.

stevec
  • 41,291
  • 27
  • 223
  • 311
  • 1
    How about using the `Rmd` in notebook fashion, i.e. executing the chunks directly? That is easy to do within RStudio. – Ralf Stubner Aug 14 '19 at 09:20
  • @RalfStubner good idea. Ideally I'd like to quickly generate the the whole html doc. The exact use case I have is that I've cloned someone's Rmd,I don't care about ~90% of it, just want to quickly knit it to check some things out (without having to make lots of finicky changes to specific code blocks). Ideally, something like `rmarkdown::render(input="myfile.Rmd", errors=FALSE)` (the errors = false part is not an actual parameter to that function) – stevec Aug 14 '19 at 09:24
  • 1
    How about adding a code chunk with `knitr::opts_chunk$set(error = TRUE)` to the beginning of the file before rendering? – Ralf Stubner Aug 14 '19 at 10:09

1 Answers1

3

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.
```
niklai
  • 376
  • 3
  • 16