使用 sweave 显示错误 [英] Displaying errors with sweave

查看:14
本文介绍了使用 sweave 显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Sweave 编写一些 R 笔记,并希望显示常见错误.例如,

I'm writing some R notes with Sweave and would like to show common errors. For example,

<<echo=TRUE, eval=TRUE>>=
x = 5
#Case matters!
x*X
@

但是,在 sweaving 时,由于 R 错误,文档将无法编译.有没有办法让 sweave 编译并显示(格式很好的)错误?

However when sweaving, the document won't compile due to the R error. Is there any way to make sweave compile and show the (nicely formated) error?

推荐答案

按照 Shane 的建议,使用

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.

这里有一个例子:http://tolstoy.newcastle.edu.au/R/help/05/09/11690.html

这篇关于使用 sweave 显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆