[R] How to say "if error"

Paul Chatfield p.s.chatfield at reading.ac.uk
Thu Jun 24 17:12:15 CEST 2010


On a similar issue, how can you detect a warning in a loop - e.g. the
following gives a warning, so I'd like to set up code to recognise that and
then carry on in a loop

x<-rnorm(2);y<-c(1,0)
ff<-glm(y/23~x, family=binomial)

so this would be incorporated into a loop that might be

x<-rnorm(10);y<-rep(c(1,0),5)
for (i in 1:10)
{ee<-glm(y~x, family=binomial)
ff<-glm(y/23~x, family=binomial)}

from which I would recognise the warning in ff and not those in ee, saving
results from ee and not from ff. The last bit would be easy adding a line
if(there_is_a_warning_message) {newvector<-NA} else {use results} but how do
you detect the warning message?

Thanks all for your feedback so far,

Paul
-- 
View this message in context: http://r.789695.n4.nabble.com/How-to-say-if-error-tp2266619p2267140.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list