Include errors in R markdown package vignette
Asked Answered
B

1

8

I'm developing an R package and have a custom function which contains a if(condition) stop("Error message") conditional. I call this function in a package vignette with the intention of generating the error message and including that in the vignette. However, this is causing vignette building to fail.

How can I force vignette building to proceed even when the code generates error messages, and retain those error messages in the vignette document?

Batson answered 28/8, 2016 at 0:52 Comment(0)
M
11

The knitr chunk options documentation says:

error: (TRUE; logical) whether to preserve errors (from stop()); by default, the evaluation will not stop even in case of errors!! if we want R to stop on errors, we need to set this option to FALSE

rmarkdown's render() function resets this to be FALSE by default (unlike knitr itself), arguably a better default. You can override this and set it back to TRUE by (I think) either

  • setting error=TRUE in the options for a particular chunk, or
  • using knitr::opts_chunk$set(error=TRUE) in an early code chunk to set the option globally.

I would suggest the former (i.e., only allow errors where you are expecting them ...)

Meit answered 28/8, 2016 at 1:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.