Capturing all warnings (with messages)

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Capturing all warnings (with messages)

Jon Clayden-2
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 like:

 > f <- function(w) print(w$message)
 > withCallingHandlers(warning("Test"),warning=f)
[1] "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)
 > options(warning.expression=quote(g()))
 > warning("Test2")
NULL

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.

 > sessionInfo()
R version 2.8.1 (2008-12-22)
i386-apple-darwin8.11.1

locale:
en_GB.UTF-8/en_US.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  splines   methods
[8] base

other attached packages:
[1] tractor.session_1.0.0   tractor.base_1.0.3      tractor.nt_1.0.2

loaded via a namespace (and not attached):
[1] tools_2.8.1

Regards,
Jon


(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/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Capturing all warnings (with messages)

Jeffrey Horner
Jon Clayden wrote on 02/04/2009 06:59 AM:

> 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 like:
>
>  > f <- function(w) print(w$message)
>  > withCallingHandlers(warning("Test"),warning=f)
> [1] "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)
>  > options(warning.expression=quote(g()))
>  > warning("Test2")
> NULL
>
> 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.

In fact, the thread did have the answer: tryCatch(). The help page is a
bear to read and comprehend, but if you do invest the time it should
convince you that you will want to use it. I find that I have to read
and reread many sections of R documentation before I can reconcile what
I want to know with what the authors are trying to tell me.

I don't comprehend everything about R's condition system, but let me see
if I can convince you that you need tryCatch() to do what you want.

Consider:

x <- function() warning("warning message")
y <- function() call_unknown_fun()
z <- function() message('message message')

Each of these functions signal conditions of a particular condition
class: simpleWarning, simpleError, and simpleMessage, respectively.

w <- function(e) str(e)

I'm going to use w  to trap the simpleWarning condition:

 > tryCatch(x(),simpleWarning=w)
List of 2
  $ message: chr "warning message"
  $ call   : language x()
  - attr(*, "class")= chr [1:3] "simpleWarning" "warning" "condition"

So tryCatch returned a list with two elements, the message and the call
that signaled the condition. In fact the list is actually an S3 object
of class simpleWarning, which inherits from warning and condition.
Reading the help page for tryCatch(), I can actually do this:

 > tryCatch(x(),condition=w)
List of 2
  $ message: chr "warning message"
  $ call   : language x()
  - attr(*, "class")= chr [1:3] "simpleWarning" "warning" "condition"

since simpleWarning inherits from condition. And in fact I can use the
condition class to trap everything I want.

 > tryCatch(y(),condition=w)
List of 2
  $ message: chr "could not find function \"call_unknown_fun\""
  $ call   : language y()
  - attr(*, "class")= chr [1:3] "simpleError" "error" "condition"

 > tryCatch(z(),condition=w)
List of 2
  $ message: chr "message message\n"
  $ call   : language message("message message")
  - attr(*, "class")= chr [1:3] "condition" "message" "simpleMessage"

(Side note: is the class hierarchy actually correct for this
simpleMessage object?)

So in summary, wrap every R expression you want to run within a single
tryCatch() call and trap all conditions with one handler for the
abstract class named 'condition'. I think that's what you want...

Jeff


>
>  > sessionInfo()
> R version 2.8.1 (2008-12-22)
> i386-apple-darwin8.11.1
>
> locale:
> en_GB.UTF-8/en_US.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  splines   methods
> [8] base
>
> other attached packages:
> [1] tractor.session_1.0.0   tractor.base_1.0.3      tractor.nt_1.0.2
>
> loaded via a namespace (and not attached):
> [1] tools_2.8.1
>
> Regards,
> Jon
>
>
> (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/
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel


--
http://biostat.mc.vanderbilt.edu/JeffreyHorner

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Capturing all warnings (with messages)

Jon Clayden-2
Dear Jeff,

Many thanks for the suggestion, but I don't think tryCatch() is the
answer, mainly because it causes code to stop executing when a warning
is signalled:

> f <- function(w) print(w$message)
> tryCatch({warning("Test"); print(3)},warning=f)
[1] "Test"

(The "print(3)" call is not run.) In this regard,
withCallingHandlers() is preferable. But either way it is untidy, at
best, to routinely put code inside one of these functions when I know
I always want to handle warnings my way. If I could set an appropriate
option when a package is loaded, or in an .Rprofile, then I should
never need to worry about whether a bit of code might generate
warnings and so should be wrapped.

Regards,
Jon

2009/2/4 Jeffrey Horner <[hidden email]>:

> Jon Clayden wrote on 02/04/2009 06:59 AM:
>>
>> 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
>> like:
>>
>>  > f <- function(w) print(w$message)
>>  > withCallingHandlers(warning("Test"),warning=f)
>> [1] "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)
>>  > options(warning.expression=quote(g()))
>>  > warning("Test2")
>> NULL
>>
>> 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.
>
> In fact, the thread did have the answer: tryCatch(). The help page is a bear
> to read and comprehend, but if you do invest the time it should convince you
> that you will want to use it. I find that I have to read and reread many
> sections of R documentation before I can reconcile what I want to know with
> what the authors are trying to tell me.
>
> I don't comprehend everything about R's condition system, but let me see if
> I can convince you that you need tryCatch() to do what you want.
>
> Consider:
>
> x <- function() warning("warning message")
> y <- function() call_unknown_fun()
> z <- function() message('message message')
>
> Each of these functions signal conditions of a particular condition class:
> simpleWarning, simpleError, and simpleMessage, respectively.
>
> w <- function(e) str(e)
>
> I'm going to use w  to trap the simpleWarning condition:
>
>> tryCatch(x(),simpleWarning=w)
> List of 2
>  $ message: chr "warning message"
>  $ call   : language x()
>  - attr(*, "class")= chr [1:3] "simpleWarning" "warning" "condition"
>
> So tryCatch returned a list with two elements, the message and the call that
> signaled the condition. In fact the list is actually an S3 object of class
> simpleWarning, which inherits from warning and condition. Reading the help
> page for tryCatch(), I can actually do this:
>
>> tryCatch(x(),condition=w)
> List of 2
>  $ message: chr "warning message"
>  $ call   : language x()
>  - attr(*, "class")= chr [1:3] "simpleWarning" "warning" "condition"
>
> since simpleWarning inherits from condition. And in fact I can use the
> condition class to trap everything I want.
>
>> tryCatch(y(),condition=w)
> List of 2
>  $ message: chr "could not find function \"call_unknown_fun\""
>  $ call   : language y()
>  - attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
>
>> tryCatch(z(),condition=w)
> List of 2
>  $ message: chr "message message\n"
>  $ call   : language message("message message")
>  - attr(*, "class")= chr [1:3] "condition" "message" "simpleMessage"
>
> (Side note: is the class hierarchy actually correct for this simpleMessage
> object?)
>
> So in summary, wrap every R expression you want to run within a single
> tryCatch() call and trap all conditions with one handler for the abstract
> class named 'condition'. I think that's what you want...
>
> Jeff
>
>
>>
>>  > sessionInfo()
>> R version 2.8.1 (2008-12-22)
>> i386-apple-darwin8.11.1
>>
>> locale:
>> en_GB.UTF-8/en_US.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  splines   methods
>> [8] base
>>
>> other attached packages:
>> [1] tractor.session_1.0.0   tractor.base_1.0.3      tractor.nt_1.0.2
>>
>> loaded via a namespace (and not attached):
>> [1] tools_2.8.1
>>
>> Regards,
>> Jon
>>
>>
>> (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/
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
> --
> http://biostat.mc.vanderbilt.edu/JeffreyHorner
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Capturing all warnings (with messages)

Jeffrey Horner
Jon Clayden wrote on 02/04/2009 12:11 PM:

> Dear Jeff,
>
> Many thanks for the suggestion, but I don't think tryCatch() is the
> answer, mainly because it causes code to stop executing when a warning
> is signalled:
>
>> f <- function(w) print(w$message)
>> tryCatch({warning("Test"); print(3)},warning=f)
> [1] "Test"
>
> (The "print(3)" call is not run.) In this regard,
> withCallingHandlers() is preferable. But either way it is untidy, at
> best, to routinely put code inside one of these functions when I know
> I always want to handle warnings my way. If I could set an appropriate
> option when a package is loaded, or in an .Rprofile, then I should
> never need to worry about whether a bit of code might generate
> warnings and so should be wrapped.

So you want your program to handle all warnings your way, but you want
to continue execution after you have trapped the warnings. What
specifically do you want your program to do with a warning once you know
what it is?

(I'd like to help you work through your problem to a solution because I
selfishly want to learn more about R's condition and restart system for
rapache's sake, my personal project. Right now, the way rapache notifies
users of R warnings and errors is crude but works.)

Jeff


>
> Regards,
> Jon
>
> 2009/2/4 Jeffrey Horner <[hidden email]>:
>> Jon Clayden wrote on 02/04/2009 06:59 AM:
>>> 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
>>> like:
>>>
>>>  > f <- function(w) print(w$message)
>>>  > withCallingHandlers(warning("Test"),warning=f)
>>> [1] "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)
>>>  > options(warning.expression=quote(g()))
>>>  > warning("Test2")
>>> NULL
>>>
>>> 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.
>> In fact, the thread did have the answer: tryCatch(). The help page is a bear
>> to read and comprehend, but if you do invest the time it should convince you
>> that you will want to use it. I find that I have to read and reread many
>> sections of R documentation before I can reconcile what I want to know with
>> what the authors are trying to tell me.
>>
>> I don't comprehend everything about R's condition system, but let me see if
>> I can convince you that you need tryCatch() to do what you want.
>>
>> Consider:
>>
>> x <- function() warning("warning message")
>> y <- function() call_unknown_fun()
>> z <- function() message('message message')
>>
>> Each of these functions signal conditions of a particular condition class:
>> simpleWarning, simpleError, and simpleMessage, respectively.
>>
>> w <- function(e) str(e)
>>
>> I'm going to use w  to trap the simpleWarning condition:
>>
>>> tryCatch(x(),simpleWarning=w)
>> List of 2
>>  $ message: chr "warning message"
>>  $ call   : language x()
>>  - attr(*, "class")= chr [1:3] "simpleWarning" "warning" "condition"
>>
>> So tryCatch returned a list with two elements, the message and the call that
>> signaled the condition. In fact the list is actually an S3 object of class
>> simpleWarning, which inherits from warning and condition. Reading the help
>> page for tryCatch(), I can actually do this:
>>
>>> tryCatch(x(),condition=w)
>> List of 2
>>  $ message: chr "warning message"
>>  $ call   : language x()
>>  - attr(*, "class")= chr [1:3] "simpleWarning" "warning" "condition"
>>
>> since simpleWarning inherits from condition. And in fact I can use the
>> condition class to trap everything I want.
>>
>>> tryCatch(y(),condition=w)
>> List of 2
>>  $ message: chr "could not find function \"call_unknown_fun\""
>>  $ call   : language y()
>>  - attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
>>
>>> tryCatch(z(),condition=w)
>> List of 2
>>  $ message: chr "message message\n"
>>  $ call   : language message("message message")
>>  - attr(*, "class")= chr [1:3] "condition" "message" "simpleMessage"
>>
>> (Side note: is the class hierarchy actually correct for this simpleMessage
>> object?)
>>
>> So in summary, wrap every R expression you want to run within a single
>> tryCatch() call and trap all conditions with one handler for the abstract
>> class named 'condition'. I think that's what you want...
>>
>> Jeff
>>
>>
>>>  > sessionInfo()
>>> R version 2.8.1 (2008-12-22)
>>> i386-apple-darwin8.11.1
>>>
>>> locale:
>>> en_GB.UTF-8/en_US.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8
>>>
>>> attached base packages:
>>> [1] stats     graphics  grDevices utils     datasets  splines   methods
>>> [8] base
>>>
>>> other attached packages:
>>> [1] tractor.session_1.0.0   tractor.base_1.0.3      tractor.nt_1.0.2
>>>
>>> loaded via a namespace (and not attached):
>>> [1] tools_2.8.1
>>>
>>> Regards,
>>> Jon
>>>
>>>
>>> (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/
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>> --
>> http://biostat.mc.vanderbilt.edu/JeffreyHorner
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>


--
http://biostat.mc.vanderbilt.edu/JeffreyHorner

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Capturing all warnings (with messages)

Jeffrey Horner
Jeffrey Horner wrote on 02/04/2009 01:19 PM:

> Jon Clayden wrote on 02/04/2009 12:11 PM:
>> Dear Jeff,
>>
>> Many thanks for the suggestion, but I don't think tryCatch() is the
>> answer, mainly because it causes code to stop executing when a warning
>> is signalled:
>>
>>> f <- function(w) print(w$message)
>>> tryCatch({warning("Test"); print(3)},warning=f)
>> [1] "Test"
>>
>> (The "print(3)" call is not run.) In this regard,
>> withCallingHandlers() is preferable. But either way it is untidy, at
>> best, to routinely put code inside one of these functions when I know
>> I always want to handle warnings my way. If I could set an appropriate
>> option when a package is loaded, or in an .Rprofile, then I should
>> never need to worry about whether a bit of code might generate
>> warnings and so should be wrapped.
>
> So you want your program to handle all warnings your way, but you want
> to continue execution after you have trapped the warnings. What
> specifically do you want your program to do with a warning once you know
> what it is?

I'm going to take a stab in the dark and presume you want to trap
warnings  so that they aren't displayed. Using options(warn=-1) and the
following could trap warnings allowing you to examine them and continue
with code execution:

 > options('warn')
$warn
[1] -1

 > system('cat /tmp/foo.R')
warning("A simple warning")
cat("continuing...\n")
 > withCallingHandlers(source('/tmp/foo.R'), warning = function(e) str(e))
List of 2
  $ message: chr "A simple warning"
  $ call   : language eval.with.vis(expr, envir, enclos)
  - attr(*, "class")= chr [1:3] "simpleWarning" "warning" "condition"
continuing...

>
> (I'd like to help you work through your problem to a solution because I
> selfishly want to learn more about R's condition and restart system for
> rapache's sake, my personal project. Right now, the way rapache notifies
> users of R warnings and errors is crude but works.)
>
> Jeff
>
>
>>
>> Regards,
>> Jon
>>
>> 2009/2/4 Jeffrey Horner <[hidden email]>:
>>> Jon Clayden wrote on 02/04/2009 06:59 AM:
>>>> 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
>>>> like:
>>>>
>>>>  > f <- function(w) print(w$message)
>>>>  > withCallingHandlers(warning("Test"),warning=f)
>>>> [1] "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)
>>>>  > options(warning.expression=quote(g()))
>>>>  > warning("Test2")
>>>> NULL
>>>>
>>>> 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.
>>> In fact, the thread did have the answer: tryCatch(). The help page is
>>> a bear
>>> to read and comprehend, but if you do invest the time it should
>>> convince you
>>> that you will want to use it. I find that I have to read and reread many
>>> sections of R documentation before I can reconcile what I want to
>>> know with
>>> what the authors are trying to tell me.
>>>
>>> I don't comprehend everything about R's condition system, but let me
>>> see if
>>> I can convince you that you need tryCatch() to do what you want.
>>>
>>> Consider:
>>>
>>> x <- function() warning("warning message")
>>> y <- function() call_unknown_fun()
>>> z <- function() message('message message')
>>>
>>> Each of these functions signal conditions of a particular condition
>>> class:
>>> simpleWarning, simpleError, and simpleMessage, respectively.
>>>
>>> w <- function(e) str(e)
>>>
>>> I'm going to use w  to trap the simpleWarning condition:
>>>
>>>> tryCatch(x(),simpleWarning=w)
>>> List of 2
>>>  $ message: chr "warning message"
>>>  $ call   : language x()
>>>  - attr(*, "class")= chr [1:3] "simpleWarning" "warning" "condition"
>>>
>>> So tryCatch returned a list with two elements, the message and the
>>> call that
>>> signaled the condition. In fact the list is actually an S3 object of
>>> class
>>> simpleWarning, which inherits from warning and condition. Reading the
>>> help
>>> page for tryCatch(), I can actually do this:
>>>
>>>> tryCatch(x(),condition=w)
>>> List of 2
>>>  $ message: chr "warning message"
>>>  $ call   : language x()
>>>  - attr(*, "class")= chr [1:3] "simpleWarning" "warning" "condition"
>>>
>>> since simpleWarning inherits from condition. And in fact I can use the
>>> condition class to trap everything I want.
>>>
>>>> tryCatch(y(),condition=w)
>>> List of 2
>>>  $ message: chr "could not find function \"call_unknown_fun\""
>>>  $ call   : language y()
>>>  - attr(*, "class")= chr [1:3] "simpleError" "error" "condition"
>>>
>>>> tryCatch(z(),condition=w)
>>> List of 2
>>>  $ message: chr "message message\n"
>>>  $ call   : language message("message message")
>>>  - attr(*, "class")= chr [1:3] "condition" "message" "simpleMessage"
>>>
>>> (Side note: is the class hierarchy actually correct for this
>>> simpleMessage
>>> object?)
>>>
>>> So in summary, wrap every R expression you want to run within a single
>>> tryCatch() call and trap all conditions with one handler for the
>>> abstract
>>> class named 'condition'. I think that's what you want...
>>>
>>> Jeff
>>>
>>>
>>>>  > sessionInfo()
>>>> R version 2.8.1 (2008-12-22)
>>>> i386-apple-darwin8.11.1
>>>>
>>>> locale:
>>>> en_GB.UTF-8/en_US.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8
>>>>
>>>> attached base packages:
>>>> [1] stats     graphics  grDevices utils     datasets  splines   methods
>>>> [8] base
>>>>
>>>> other attached packages:
>>>> [1] tractor.session_1.0.0   tractor.base_1.0.3      tractor.nt_1.0.2
>>>>
>>>> loaded via a namespace (and not attached):
>>>> [1] tools_2.8.1
>>>>
>>>> Regards,
>>>> Jon
>>>>
>>>>
>>>> (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/
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>> --
>>> http://biostat.mc.vanderbilt.edu/JeffreyHorner
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>
>


--
http://biostat.mc.vanderbilt.edu/JeffreyHorner

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Capturing all warnings (with messages)

hadley wickham
In reply to this post by Jon Clayden-2
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.

Hadley

On Wed, Feb 4, 2009 at 6:59 AM, Jon Clayden <[hidden email]> 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
> like:
>
>> f <- function(w) print(w$message)
>> withCallingHandlers(warning("Test"),warning=f)
> [1] "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)
>> options(warning.expression=quote(g()))
>> warning("Test2")
> NULL
>
> 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.
>
>> sessionInfo()
> R version 2.8.1 (2008-12-22)
> i386-apple-darwin8.11.1
>
> locale:
> en_GB.UTF-8/en_US.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  splines   methods
> [8] base
>
> other attached packages:
> [1] tractor.session_1.0.0   tractor.base_1.0.3      tractor.nt_1.0.2
>
> loaded via a namespace (and not attached):
> [1] tools_2.8.1
>
> Regards,
> Jon
>
>
> (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/
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



--
http://had.co.nz/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Capturing all warnings (with messages)

Jon Clayden-2
Jeff, Hadley,

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.

Jon

2009/2/4 hadley wickham <[hidden email]>:

> 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.
>
> Hadley
>
> On Wed, Feb 4, 2009 at 6:59 AM, Jon Clayden <[hidden email]> 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
>> like:
>>
>>> f <- function(w) print(w$message)
>>> withCallingHandlers(warning("Test"),warning=f)
>> [1] "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)
>>> options(warning.expression=quote(g()))
>>> warning("Test2")
>> NULL
>>
>> 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.
>>
>>> sessionInfo()
>> R version 2.8.1 (2008-12-22)
>> i386-apple-darwin8.11.1
>>
>> locale:
>> en_GB.UTF-8/en_US.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  splines   methods
>> [8] base
>>
>> other attached packages:
>> [1] tractor.session_1.0.0   tractor.base_1.0.3      tractor.nt_1.0.2
>>
>> loaded via a namespace (and not attached):
>> [1] tools_2.8.1
>>
>> Regards,
>> Jon
>>
>>
>> (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/
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
>
>
> --
> http://had.co.nz/
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Capturing all warnings (with messages)

William Dunlap
In SV3 (or Splus prior to 5.0) one could redefine
the .Program expression, which
by default was close to print(eval(parse(stdin())) along
with some extras like printing warnings and errors in
certain ways and recording input in a .Audit file.   I
once wrote toy .Programs that used select() to
listen for data arriving on a socket and for commands
from stdin.  The data would be appended to a certain
dataset as it arrived and the user could ask to replot
it whenever he wanted.  You could use options("warning.expression")
and try() to present warnings and errors to the user in
whatever way you wanted.  I think it was used in old
versions of Splus on Windows to implement the connection
to the GUI.

Is this the sort of functionality you are looking for?

If you are writing a front-end for R the .Program is not
needed, as your front end can easily wrap boilerplate,
like eval.with.details, around whatever text the user types in.


Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com  

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Jon Clayden
> Sent: Wednesday, February 04, 2009 4:31 PM
> To: hadley wickham
> Cc: [hidden email]
> Subject: Re: [Rd] Capturing all warnings (with messages)
>
> Jeff, Hadley,
>
> 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.
>
> Jon
>
> 2009/2/4 hadley wickham <[hidden email]>:
> > 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.
> >
> > Hadley
> >
> > On Wed, Feb 4, 2009 at 6:59 AM, Jon Clayden
> <[hidden email]> 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
> >> like:
> >>
> >>> f <- function(w) print(w$message)
> >>> withCallingHandlers(warning("Test"),warning=f)
> >> [1] "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)
> >>> options(warning.expression=quote(g()))
> >>> warning("Test2")
> >> NULL
> >>
> >> 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.
> >>
> >>> sessionInfo()
> >> R version 2.8.1 (2008-12-22)
> >> i386-apple-darwin8.11.1
> >>
> >> locale:
> >> en_GB.UTF-8/en_US.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8
> >>
> >> attached base packages:
> >> [1] stats     graphics  grDevices utils     datasets  
> splines   methods
> >> [8] base
> >>
> >> other attached packages:
> >> [1] tractor.session_1.0.0   tractor.base_1.0.3      
> tractor.nt_1.0.2
> >>
> >> loaded via a namespace (and not attached):
> >> [1] tools_2.8.1
> >>
> >> Regards,
> >> Jon
> >>
> >>
> >> (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/
> >>
> >> ______________________________________________
> >> [hidden email] mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-devel
> >>
> >
> >
> >
> > --
> > http://had.co.nz/
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Capturing all warnings (with messages)

Luke Tierney
Kurt Hornik and I have discussed off an on a mechanism for setting
default condition handlers.  So far we haven't come up with anything
satisfactory but we may yet.  In some ways this would be easier if the
top level was written in R, along the lines of .Program, so I've
played around with that a bit, but not to the point where it is usable
in production yet.

luke

On Wed, 4 Feb 2009, William Dunlap wrote:

> In SV3 (or Splus prior to 5.0) one could redefine
> the .Program expression, which
> by default was close to print(eval(parse(stdin())) along
> with some extras like printing warnings and errors in
> certain ways and recording input in a .Audit file.   I
> once wrote toy .Programs that used select() to
> listen for data arriving on a socket and for commands
> from stdin.  The data would be appended to a certain
> dataset as it arrived and the user could ask to replot
> it whenever he wanted.  You could use options("warning.expression")
> and try() to present warnings and errors to the user in
> whatever way you wanted.  I think it was used in old
> versions of Splus on Windows to implement the connection
> to the GUI.
>
> Is this the sort of functionality you are looking for?
>
> If you are writing a front-end for R the .Program is not
> needed, as your front end can easily wrap boilerplate,
> like eval.with.details, around whatever text the user types in.
>
>
> Bill Dunlap
> TIBCO Software Inc - Spotfire Division
> wdunlap tibco.com
>
>> -----Original Message-----
>> From: [hidden email]
>> [mailto:[hidden email]] On Behalf Of Jon Clayden
>> Sent: Wednesday, February 04, 2009 4:31 PM
>> To: hadley wickham
>> Cc: [hidden email]
>> Subject: Re: [Rd] Capturing all warnings (with messages)
>>
>> Jeff, Hadley,
>>
>> 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.
>>
>> Jon
>>
>> 2009/2/4 hadley wickham <[hidden email]>:
>>> 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.
>>>
>>> Hadley
>>>
>>> On Wed, Feb 4, 2009 at 6:59 AM, Jon Clayden
>> <[hidden email]> 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
>>>> like:
>>>>
>>>>> f <- function(w) print(w$message)
>>>>> withCallingHandlers(warning("Test"),warning=f)
>>>> [1] "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)
>>>>> options(warning.expression=quote(g()))
>>>>> warning("Test2")
>>>> NULL
>>>>
>>>> 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.
>>>>
>>>>> sessionInfo()
>>>> R version 2.8.1 (2008-12-22)
>>>> i386-apple-darwin8.11.1
>>>>
>>>> locale:
>>>> en_GB.UTF-8/en_US.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8
>>>>
>>>> attached base packages:
>>>> [1] stats     graphics  grDevices utils     datasets
>> splines   methods
>>>> [8] base
>>>>
>>>> other attached packages:
>>>> [1] tractor.session_1.0.0   tractor.base_1.0.3
>> tractor.nt_1.0.2
>>>>
>>>> loaded via a namespace (and not attached):
>>>> [1] tools_2.8.1
>>>>
>>>> Regards,
>>>> Jon
>>>>
>>>>
>>>> (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/
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>
>>>
>>>
>>> --
>>> http://had.co.nz/
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
> ______________________________________________
> [hidden email] 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:      [hidden email]
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Capturing all warnings (with messages)

Philippe Grosjean
Hello,

There is a function captureAll() in the svMisc package on CRAN. Although
in its current version, it simulates textual output you got at the
console, it should be rather easy to modify it to return separately
output, errors and warnings. There is one point to consider: the
function cannot catch some output from c code, and it does not work well
with R code needing interaction at the console, like browser() for
instance. For the rest, its handling of output (visible versus invisible
output) and of warnings, including management of options(warn = ) is
very similar to what is done at the console.
Best,

Philippe
..............................................<°}))><........
  ) ) ) ) )
( ( ( ( (    Prof. Philippe Grosjean
  ) ) ) ) )
( ( ( ( (    Numerical Ecology of Aquatic Systems
  ) ) ) ) )   Mons-Hainaut University, Belgium
( ( ( ( (
..............................................................

[hidden email] wrote:

> Kurt Hornik and I have discussed off an on a mechanism for setting
> default condition handlers.  So far we haven't come up with anything
> satisfactory but we may yet.  In some ways this would be easier if the
> top level was written in R, along the lines of .Program, so I've
> played around with that a bit, but not to the point where it is usable
> in production yet.
>
> luke
>
> On Wed, 4 Feb 2009, William Dunlap wrote:
>
>> In SV3 (or Splus prior to 5.0) one could redefine
>> the .Program expression, which
>> by default was close to print(eval(parse(stdin())) along
>> with some extras like printing warnings and errors in
>> certain ways and recording input in a .Audit file.   I
>> once wrote toy .Programs that used select() to
>> listen for data arriving on a socket and for commands
>> from stdin.  The data would be appended to a certain
>> dataset as it arrived and the user could ask to replot
>> it whenever he wanted.  You could use options("warning.expression")
>> and try() to present warnings and errors to the user in
>> whatever way you wanted.  I think it was used in old
>> versions of Splus on Windows to implement the connection
>> to the GUI.
>>
>> Is this the sort of functionality you are looking for?
>>
>> If you are writing a front-end for R the .Program is not
>> needed, as your front end can easily wrap boilerplate,
>> like eval.with.details, around whatever text the user types in.
>>
>>
>> Bill Dunlap
>> TIBCO Software Inc - Spotfire Division
>> wdunlap tibco.com
>>
>>> -----Original Message-----
>>> From: [hidden email]
>>> [mailto:[hidden email]] On Behalf Of Jon Clayden
>>> Sent: Wednesday, February 04, 2009 4:31 PM
>>> To: hadley wickham
>>> Cc: [hidden email]
>>> Subject: Re: [Rd] Capturing all warnings (with messages)
>>>
>>> Jeff, Hadley,
>>>
>>> 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.
>>>
>>> Jon
>>>
>>> 2009/2/4 hadley wickham <[hidden email]>:
>>>> 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.
>>>>
>>>> Hadley
>>>>
>>>> On Wed, Feb 4, 2009 at 6:59 AM, Jon Clayden
>>> <[hidden email]> 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
>>>>> like:
>>>>>
>>>>>> f <- function(w) print(w$message)
>>>>>> withCallingHandlers(warning("Test"),warning=f)
>>>>> [1] "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)
>>>>>> options(warning.expression=quote(g()))
>>>>>> warning("Test2")
>>>>> NULL
>>>>>
>>>>> 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.
>>>>>
>>>>>> sessionInfo()
>>>>> R version 2.8.1 (2008-12-22)
>>>>> i386-apple-darwin8.11.1
>>>>>
>>>>> locale:
>>>>> en_GB.UTF-8/en_US.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8
>>>>>
>>>>> attached base packages:
>>>>> [1] stats     graphics  grDevices utils     datasets
>>> splines   methods
>>>>> [8] base
>>>>>
>>>>> other attached packages:
>>>>> [1] tractor.session_1.0.0   tractor.base_1.0.3
>>> tractor.nt_1.0.2
>>>>>
>>>>> loaded via a namespace (and not attached):
>>>>> [1] tools_2.8.1
>>>>>
>>>>> Regards,
>>>>> Jon
>>>>>
>>>>>
>>>>> (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/
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> http://had.co.nz/
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel