Include errors in R markdown package vignette

拜拜、爱过 提交于 2019-12-08 21:33:15

问题


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?


回答1:


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 ...)



来源:https://stackoverflow.com/questions/39187085/include-errors-in-r-markdown-package-vignette

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