[Rd] Capturing all warnings (with messages)
j.clayden at ucl.ac.uk
Thu Feb 5 01:31:10 CET 2009
Many thanks for your responses. The eval.with.details package sounds
interesting and I'll certainly take a closer look, but it still seems
to me that these approaches are focussed on trapping warnings within
specific snippets of code rather than changing the way all warnings
(including those in standard packages) are reported.
This ability would surely be useful anytime that you wish to change
the reporting of warnings from the default. Say, for example, that you
wanted to include a timestamp with each warning message. You'd do it,
I would expect, by writing a function that checks the time and formats
the message appropriately. This is the kind of thing I'm after -- I
hope this clarifies things a bit more.
The warn.expression option *appears* to provide a way to do what I
want, but because the warning is not passed to the expression (or so
it seems), and last.warning is not set before the expression is
evaluated, the expression can only know that *some* warning condition
has been raised, not *which* one. Perhaps there is a reason that
last.warning cannot be set first (?), but this limits the usefulness
of the option.
2009/2/4 hadley wickham <h.wickham at gmail.com>:
> Hi Jon,
> I have an in-development package that attempts to do this. It's
> called eval.with.details and is available from
> http://github.com/hadley/eval.with.details. As you might guess, it's
> a version of eval that captures all details like messages, warnings,
> errors and output so you can do whatever you want with them. It
> captures them in the way Jeff Horner describes - but there are a lot
> of fiddly details to get right.
> Unfortunately there isn't any documentation yet, but the majority of
> what you're interested in is present in eval.r. The code has been
> fairly well tested - I'm using it in my own implementation of a sweave
> like system.
> On Wed, Feb 4, 2009 at 6:59 AM, Jon Clayden <j.clayden at ucl.ac.uk> wrote:
>> Dear all,
>> For an open-source project that I'm working on (1), which uses R for all its
>> heavy lifting but includes a wrapper shell script, I was hoping to find a
>> way to capture all warnings (and, in fact, errors too), and handle them in
>> my own way. I realise I can do this for a single expression using something
>>> f <- function(w) print(w$message)
>>  "Test"
>> Warning message:
>> In withCallingHandlers(warning("Test"), warning = f) : Test
>> But I would like to capture all warnings, globally. The "warning.expression"
>> option doesn't seem to allow an argument, and I can't seem to use
>> "last.warning" to get at the message either:
>>> g <- function() print(last.warning$message)
>> Could anyone tell me whether there's a way to do this, please? An old thread
>> on this topic seemed to go unresolved (2), and I've skimmed RNEWS and I
>> don't see anything about this since then.
>> R version 2.8.1 (2008-12-22)
>> attached base packages:
>>  stats graphics grDevices utils datasets splines methods
>>  base
>> other attached packages:
>>  tractor.session_1.0.0 tractor.base_1.0.3 tractor.nt_1.0.2
>> loaded via a namespace (and not attached):
>>  tools_2.8.1
>> (1) http://code.google.com/p/tractor/
>> (2) http://finzi.psych.upenn.edu/R/Rhelp02/archive/61872.html
>> Jonathan D. Clayden, Ph.D.
>> Research Fellow
>> Radiology and Physics Unit
>> UCL Institute of Child Health
>> 30 Guilford Street
>> LONDON WC1N 1EH
>> United Kingdom
>> t | +44 (0)20 7905 2708
>> f | +44 (0)20 7905 2358
>> w | www.homepages.ucl.ac.uk/~sejjjd2/
>> R-devel at r-project.org mailing list
> R-devel at r-project.org mailing list
More information about the R-devel