From wdunlap at tibco.com  Mon Nov 23 17:53:26 2015
From: wdunlap at tibco.com (William Dunlap)
Date: Mon, 23 Nov 2015 08:53:26 -0800
Subject: [Rd] capturing warnings using capture.output
In-Reply-To: <CAPp_+=e8fcyxCCqVwxWuYZpZ+sXGJbm04Mw0Zf8MUuht9dh3kA@mail.gmail.com>
References: <CAPp_+=e8fcyxCCqVwxWuYZpZ+sXGJbm04Mw0Zf8MUuht9dh3kA@mail.gmail.com>
Message-ID: <CAF8bMca7sZTX+RtWnn44fUHsxWo2KGMntPTG4rh8380eAxForA@mail.gmail.com>

When options("warn") is 0, the default, the warning is not
printed until capture.output is done.  Use warn=1 to capture
the warnings as messages:

> options(warn=0)
> txt0 <- capture.output({message("A message"); warning("A warning")}, type="message")
Warning message:
In eval(expr, envir, enclos) : A warning
> options(warn=1)
> txt1 <- capture.output({message("A message"); warning("A warning")}, type="message")
> txt0
[1] "A message"
> txt1
[1] "A message"
[2] "Warning in eval(expr, envir, enclos) : A warning"
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Nov 23, 2015 at 2:31 AM, Richard Cotton <richierocks at gmail.com> wrote:
> >From the Details section of ?capture.output:
>
> Messages sent to stderr() (including those from message, warning and stop)
> are captured by type = "message". Note that this can be "unsafe" and should
> only be used with care.
>
> Capturing messages works as expected:
>
> capture.output(message("!!!"), type = "message")
> ## [1] "!!!"
>
> Capturing warnings doesn't seems to work:
>
> capture.output(warning("!!!"), type = "message")
> ## character(0)
> ## Warning message:
> ## In eval(expr, envir, enclos) : !!!
>
> Is the documentation wrong, or is this a bug, or am I doing doing silly?
>
> --
> Regards,
> Richie
>
> Learning R
> 4dpiecharts.com
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] capturing warnings using capture.output
William Dunlap