[R] Subclassing lm

Uwe Ligges ligges at statistik.uni-dortmund.de
Sun Oct 12 22:21:13 CEST 2003


rlee at fpcc.net wrote:
> 
> I'd trying to subclass the "lm" class to produce a "mylm" class whose
> instances behave like lm objects (are accepted by methods like summary.lm)
> but have additional data or slots of my own design.
> 
> For starters:
> 
> setClass("mylm", "lm")
> 
> produces the somewhat cryptic:
>  Warning message:
> Old-style (``S3'') class "mylm" supplied as a superclass of "mylm", but no
> automatic conversion will be peformed for S3 classes in:
> .validDataPartClass(cl, name)
> 
> What does this imply?
> 

I've never mixed S3 and S4 methods, so excuse my ignorance here (and I'm
only answering because I haven't seen another reply).

Since there is no formal definition of a representation of "lm" (an S3
class!): Does it really make sense for you to extend it with S4 methods?
If not, I'd rather use the "old" construct to tell the object about
inheritance:
class(anymylmobject) <- c("mylm", "lm")

Anyway, what you are looking for is 
  ?setOldClass
in my expectation, as in:
  setOldClass(c("mylm", "lm"))
Reading that help file carefully might help. 
In particular, you can get a bit of S4 behaviour (e.g. you can defining
S4 Classes and Methods), but you'll "just" get a virtual class, so the
requested definition of formal slots will be still a problem.

Uwe Ligges




More information about the R-help mailing list