[R] Catching an error with lm()

Gabor Grothendieck ggrothendieck at gmail.com
Tue May 24 12:46:19 CEST 2005


On 5/24/05, Ajay Narottam Shah <ajayshah at mayin.org> wrote:
> Folks,
> 
> I'm in a situation where I do a few thousand regressions, and some of
> them are bad data. How do I get back an error value (return code such
> as NULL) from lm(), instead of an error _message_?
> 
> Here's an example:
> 
> > x <- c(NA, 3, 4)
> > y <- c(2, NA, NA)
> > d <- lm(y ~ x)
> Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
>        0 (non-NA) cases
> > str(d)
> Error in str(d) : Object "d" not found
> 
> My question is: How do I force lm() to quietly send back an error code
> like NULL? I am happy to then look at is.null(d) and handle it
> accordingly. I am stuck because when things go wrong, there is no
> object d to analyse!
> 
> (My production situation is a bit more complex. It is costly for me to
> first verify that the data is sound. I'd like to toss it into lm() and
> get an error code for null data).

See this post from yesterday:

https://www.stat.math.ethz.ch/pipermail/r-help/2005-May/070606.html




More information about the R-help mailing list