Hi! I'm trying to catch all warning-messages for special handling. It seems options (warning.expression=myfunc ()) can be used for that. However, the question is: How can I get at the actual warning in myfunc ()? Apparently in S, you can use .C("get_last_message") for that. Is there a similar mechanism in R? Thanks for your help! Thomas
?warnings Also see ?conditions Note that both were suggested by help.search('warning') -- Please do make full use of R's internal documentation before posting. -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA "The business of the statistician is to catalyze the scientific learning process." - George E. P. Box> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Thomas > Friedrichsmeier > Sent: Thursday, September 22, 2005 9:14 AM > To: r-help at stat.math.ethz.ch > Subject: [R] warning.expression? > > Hi! > > I'm trying to catch all warning-messages for special > handling. It seems > options (warning.expression=myfunc ()) can be used for that. > However, the > question is: How can I get at the actual warning in myfunc > ()? Apparently in > S, you can use .C("get_last_message") for that. Is there a > similar mechanism > in R? > > Thanks for your help! > Thomas > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
You might be interested in 'tryCatch' to catch warnings. -roger Thomas Friedrichsmeier wrote:> Hi! > > I'm trying to catch all warning-messages for special handling. It seems > options (warning.expression=myfunc ()) can be used for that. However, the > question is: How can I get at the actual warning in myfunc ()? Apparently in > S, you can use .C("get_last_message") for that. Is there a similar mechanism > in R? > > Thanks for your help! > Thomas > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Roger D. Peng http://www.biostat.jhsph.edu/~rpeng/
> I'm afraid this does not make sense to me. An "interactive session" is > not some monolithic blob. It is a sequence of one or more (often very > many) discreet interactions. Any one of these may produce an > exceptional condition, and it seems to me that each individual > interaction that elicits an exception should be handled independently > and if it does produce an exceptional condition, that should be > reported as soon as it occurs. Things should then be cleaned up, as > necessary and feasible, and the interactive session should be allowed > to continue.Sorry, indeed I was simplifying beyond recognition. Actually, I'm writing a GUI front-end to R, and what I called an "interactive session" is technically not an interactive session in R at all, but would only seem like one to the user. In the GUI, there are R expressions being run from some application code, but also there is a sort of console, where the user can interact with R more or less directly, like they would in a regular interactive session. What I mean by "special handling", then, is not so much reacting to the warnings/errors. Rather, the thing I'm really trying to do, is just to figure out, which output is "regular" output, which is a warning, and which is an error. All output gets displayed right in time, for the user to react to. However, one use case would be to mark up all warnings in a certain color and all errors in another. Also, for commands running for GUI-actions, it would be nice to inform the user - if applicable - "there have been the following warnings" or "an error occurred, see below". So basically, my programmer's dream would be to have three simple callbacks: one each for "regular output", warnings and errors. While it's not quite as simple, I have most things in place: I'm catching all that would be going to stdout via ptr_R_WriteConsole. I'm catching the errors using my own callback in options (error=...). Now all I need is a way to find out about warnings. It seemed to me, options (warning.expression=...) would be a neat way to do that, but I could not find out, how to use it. Hope that clarifies what I need this for. BTW, the project in question is this: http://rkward.sf.net Regards Thomas