[R] how to trap any warnings from an R function

Boryeu Mao B.Mao at cerep.com
Tue Apr 30 18:52:54 CEST 2002

Thanks for the reply.  The problem that I have in a nutshell is the

usertest <- function {
 reg<-polr(act~., data=mm)

For some data, NaN's are produced (in sqrt(diag(vc))), and I'd like to trap
this condition and any other warnings, so that a negative value, say, can be
returned to the calling function to indicate the warning condition.
Warnings from 
summary() are produced and placed in 'last.warning' but that is accessible
only at the top-level, not within usertest(); I've tried setting 'warn' in
options() but hadn't found a way to do this.  I'm still searching various
docs for any ideas, and it seems to be something that might be quite
straightforward.  Any points/ideas are appreciated.   Thanks!

-----Original Message-----
From: Jason Turner [mailto:jasont at indigoindustrial.co.nz]
Sent: Tuesday, April 30, 2002 12:23 PM
To: Boryeu Mao
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] how to trap any warnings from an R function

On Mon, Apr 29, 2002 at 12:43:56PM -0700, Boryeu Mao wrote:
> Within an user function, how are the warnings from an R function be
> (such that some proper actions can be taken)?  

One way is with try()


Indigo Industrial Controls Ltd.
jasont at indigoindustrial.co.nz
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list