[R] Making an S3 object act like a data.frame

hadley wickham h.wickham at gmail.com
Wed Mar 8 00:28:47 CET 2006

> I tend to have to use trial and error myself.  Here is another
> possibility.

That's got the subsetting solved, so here's the next challenge

> lm(x ~ y, z)
Error in as.data.frame.default(data) : cannot coerce class "myobj"
into a data.frame
> as.data.frame.myobj <- function(x) x[[1]]
> lm(x ~ y, z)
Error in eval(expr, envir, enclos) : numeric 'envir' arg not of length one

I'm guessing this is pretty much impossible to get around, because
there is no way to tell eval how to deal with myobj type objects, and
lm only dispatches based on the type of the first argument.


More information about the R-help mailing list