Displaying errors with sweave

烈酒焚心 提交于 2019-11-30 18:51:11

As Shane suggests, use

<<echo=TRUE,eval=FALSE>> 

for the code that will error, but you want to display, and then again with

<<echo=FALSE,eval=TRUE,results=verbatim>> 

but with the same code wrapped in a try.

There's an example here: http://tolstoy.newcastle.edu.au/R/help/05/09/11690.html

This is a non-issue with knitr, the "next generation Sweave", if I may say so. It displays errors and warnings by default, which was difficult or impossible in Sweave, along with a plethora of other nice features (like syntax coloring, PGF integration and plot animation, for starters). It is developed and maintained actively, too.

Sweave code must be converted once using the function Sweave2knitr provided by the same package.

Wrap your error in a try() command. Then it will keep running:

> {print(1); try(x*X); print(2)}
[1] 1
Error in try(x * X) : object 'X' not found
[1] 2
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!