Alex Rivera | Logout

How can I redirect R warning messages to STDOUT?

Asked 2010-11-06T11:26:00.223
11

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?

Edit
Report

1 Answer

8

Look at the help page for sink():

‘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.

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).

answered 2010-11-06T13:07:38.217

Your Answer