Suppressing Error Messages in knitr

ぐ巨炮叔叔 提交于 2019-12-01 09:43:23

Errors have their own dedicated hook function, stored in the environment accessed by knit_hooks$get(). Here, for your enlightenment, is the complete list of those functions:

names(knit_hooks$get())
# [1] "source"   "output"   "warning"  "message"  "error"    "plot"    
# [7] "inline"   "chunk"    "document"

To suppress warnings, just overwrite the default error hook function with one that takes the required arguments, but doesn't return anything at all.

\documentclass{article}
\begin{document}

<<setup, include=FALSE, cache=FALSE>>=
muffleError <- function(x,options) {}
knit_hooks$set(error=muffleError)
@

<<Test>>=
1:10
X
@
\end{document}

Which, upon compilation, yields the following

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