R-alpha: inheritance ([.ts)

Thomas Lumley thomas@biostat.washington.edu
Thu, 11 Dec 1997 10:59:39 -0800 (PST)


On Thu, 11 Dec 1997, Paul Gilbert wrote:

> While commenting out the previously mentioned warning seems to work, I have been
> reflecting on this problem and there seems to be an issue wrt inheritance that I
> do not understand properly. Perhaps some gurus could comment.

There is no real "inheritance" mechanism in R.  Objects have a list of
classes, and UseMethod/NextMethod search this list from left to right,
pasting the class name on to the generic method name, until a function is
found. The ability to mimic inheritance relies on class names being
unique, so that, for example gee inherits from glm which inherits from lm.


> As mentioned previously, I have a class "tframe" with more specific classes
> indicating how time is being represented, such as
> > class(tframe(data))
> [1] "ts"     "tframe"
> and in R0.60 "[.ts" produces warning messages when I use tframe(data)[2].
 
> Does the fact that there is a class "ts" mean that one should not have another
> class with "ts" as its more specific class? This seems like a pretty severe
> limitation.

Yes it does. It is a limitation especially as there is only one namespace.
It is also unfortunate that a lot of people have used method-like names
the other way around, so that eg cox.zph is a proportional hazards test (z
ph) for a cox model, not a "cox" for a "zph" object.

The fix to this is to use something like 
	c("ts.tsframe", "tsframe")
for a more specific ts subclass of tsframe.  It's a bit ugly, but it
works.

	-thomas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._