如何将 R 警告消息重定向到 STDOUT? [英] How can I redirect R warning messages to STDOUT?
问题描述
我正在使用网格引擎来运行 R 脚本.在此设置下,STDERR 受到重视,因此我希望保持干净,并且只将真实/严重/致命错误打印到 STDERR.
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.
问题是我的 R 脚本生成了各种 STDERR 消息,这些消息并不是真正严重的警告……例如,scan
似乎向 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.
我可以(从 R 中)将 STDERR 重定向到 STDOUT 吗?
Can I redirect (from within R) STDERR to STDOUT?
推荐答案
查看sink()
的帮助页面:
‘sink’将 R 输出转移到一个连接.如果 ‘file’ 是一个字符字符串,将建立具有该名称的文件连接转移的持续时间.
‘sink’ diverts R output to a connection. If ‘file’ is a character string, a file connection with that name will be established for the duration of the diversion.
正常的 R 输出(到连接‘stdout’)被转移到默认类型=输出"".只有提示和(大多数)消息继续出现在控制台上.发送到‘stderr()’的消息(包括来自消息"、警告"和停止"的那些)可以是被‘sink(type = "message")’转移(见下文).
Normal R output (to connection ‘stdout’) is diverted by the default ‘type = "output"’. Only prompts and (most) messages continue to appear on the console. Messages sent to ‘stderr()’ (including those from ‘message’, ‘warning’ and ‘stop’) can be diverted by ‘sink(type = "message")’ (see below).
这篇关于如何将 R 警告消息重定向到 STDOUT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!