显示 sweave 的错误
我正在使用 Sweave 编写一些 R 笔记,并希望显示常见错误。例如,
<<echo=TRUE, eval=TRUE>>=
x = 5
#Case matters!
x*X
@
但是在 sweaving 时,由于 R 错误,文档将无法编译。有没有办法让 sweave 编译并显示(格式良好的)错误?
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
@
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于“下一代
Sweave”
”,如果我可以这么说的话。它默认显示错误和警告,这在knitr
来说,这不是问题Sweave
中是很困难或不可能的,此外还有大量其他不错的功能(例如语法着色、PGF 集成和绘图动画,对于初学者来说)。它也得到积极的开发和维护。Sweave
代码必须使用同一包提供的函数Sweave2knitr
转换一次。This is a non-issue with
knitr
, the "next generationSweave
", if I may say so. It displays errors and warnings by default, which was difficult or impossible inSweave
, 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 functionSweave2knitr
provided by the same package.正如 Shane 建议的那样,使用
会出错但您想要显示的代码,然后再次使用
but 将相同的代码包装在 try 中。
这里有一个例子:
http://tolstoy.newcastle.edu.au/R/help /05/09/11690.html
As Shane suggests, use
for the code that will error, but you want to display, and then again with
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
将错误包含在
try()
命令中。然后它会继续运行:Wrap your error in a
try()
command. Then it will keep running: