如何将 R 警告消息重定向到 STDOUT?
我正在使用网格引擎来运行 R 脚本。在此设置下,STDERR 受到认真对待,因此我想保持其干净,并且仅将真正/严重/致命的错误打印到 STDERR。
问题是我的 R 脚本生成各种 STDERR 消息,这些消息并不是真正严重的警告...例如, scan
似乎将其读取的项目数打印到 STDERR。
我可以(从 R 内部)将 STDERR 重定向到 STDOUT 吗?
I'm using a grid engine to run R scripts. The STDERR is taken seriously under this setup, so I would like to keep it clean and have only real/serious/fatal errors printed to STDERR.
The problem is my R script generate various STDERR messages which are not really serious warnings... for example, scan
seems to print to STDERR the number of items it read.
Can I redirect (from within R) STDERR to STDOUT?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看
sink()
的帮助页面:Look at the help page for
sink()
:@Dirk 已经提供了答案,但我想补充一点,您可以使用 stdout() 来连接到 STDOUT。您可以在任何输出函数中使用它来直接输出。
@Dirk already provided the answer, but I would just add that you can use
stdout()
to get a connection to the STDOUT. You can use this in any output function to direct output there.隔离错误的一种方法是使用 try catch,在主块中,所有内容都发送到 stdout,然后捕获代码引发的任何错误并将其发送到 stderr。
这只会处理代码中引发的错误,而不是记录错误消息,但可能是您的解决方案。
One way to segregate out an error is to use try catch, in the main block everything is send to stdout, then any errors thrown by the code are caught and sent to stderr.
This will only handle errors that are thrown in the code, rather than logging of error messages, but might be a solution for you.