[R] Redirecting Messages and Errors to a file

McGehee, Robert Robert.McGehee at geodecapital.com
Wed Jul 27 16:54:47 CEST 2005

Ahh, I misunderstood the help page. I took that since the default values
for type were c("output", "message"), that both the output _and_ the
messages were simultaneously being redirected (else why not just make
the default "output"). I see that this is not the case (as noted in the

After specifying type = "message", I was also able to successfully send
off the error messages to a file, but not at the same time as sending
the output. That is, do I need to have two sink files, one for errors,
one for output and then append them before mailing? I'd prefer a way of
sending all output/messages to the same file to preserve the order of
the messages/output, if this is possible.


-----Original Message-----
From: Thomas Lumley [mailto:tlumley at u.washington.edu] 
Sent: Wednesday, July 27, 2005 10:37 AM
To: McGehee, Robert
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Redirecting Messages and Errors to a file

On Wed, 27 Jul 2005, McGehee, Robert wrote:

> However, the sink() does not seem to be capturing the error messages
> I would have hoped. That is, if the R-script is {print("abc");
> stop("def")}, the print output is captured to the file, the stop error
> message is not, and instead sent to the screen.
> Any thoughts on how to do this such that everything is sent to the
> for emailing? Perhaps something different all together?

There is a separate output connection for errors.  The help page for 
sink() describes how to divert it, and warns of risks in doing so.


More information about the R-help mailing list