From luke at stat.uiowa.edu  Tue Sep  5 17:53:05 2006
From: luke at stat.uiowa.edu (Luke Tierney)
Date: Tue, 5 Sep 2006 10:53:05 -0500 (CDT)
Subject: [Rd] Capturing warnings with capture.output
In-Reply-To: <f8e6ff050609050813t46851a59xf4325fd813e6d503@mail.gmail.com>
References: <f8e6ff050608290746x420b56e7i5c7d7fabea9a9c98@mail.gmail.com>
	<971536df0608290807m607951f8j6ded7cba36e7c5c9@mail.gmail.com>
	<f8e6ff050609050813t46851a59xf4325fd813e6d503@mail.gmail.com>
Message-ID: <Pine.LNX.4.64.0609051052440.30445@nokomis.stat.uiowa.edu>

Look at how suppressWarnings does this.

Best,

luke

On Tue, 5 Sep 2006, hadley wickham wrote:

>> Something like this which displays the warnings and also writes
>> them to out so that they are captured:
>
> Is it possible to not display the warnings (just write them out) ?
>
> Hadley
>
>
>
>
>>
>> out <- capture.output(
>>    withCallingHandlers({
>>         print(1)
>>         warning("A warning.")
>>         print(2)
>>         warning("Another warning.")
>>         print(3)
>>    }, warning = function(x) cat(x$message, "\n"))
>> )
>>
>> print(out)
>>
>>
>> On 8/29/06, hadley wickham <h.wickham at gmail.com> wrote:
>>> Is there any way to include warnings in the output from capture.output?  eg:
>>>
>>> a <- capture.output(warning("test"))
>>> all.equal(a, "Warning message: \n test ")
>>>
>>> Conceptually, this seems like redirecting stderr to stdout, or somehow
>>> changing warning to simple print it's output.  I've had a look at
>>> tryCatch and using a warning handler, but this terminates execution at
>>> the warning.
>>>
>>> Thanks,
>>>
>>> Hadley
>>>
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:      luke at stat.uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu




[Rd] Capturing warnings with capture.output
Luke Tierney