Re: [R] Catching an error with lm()

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue 24 May 2005 - 20:46:19 EST

On 5/24/05, Ajay Narottam Shah <ajayshah@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



R-help@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 Received on Tue May 24 20:52:46 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:01 EST