Re: [Rd] '"ts" treated as a registered S3 class, but keep its "structure" behaviour' ?

From: John Chambers <jmc_at_r-project.org>
Date: Thu, 07 Aug 2008 12:11:52 -0400

Yohan Chalabi wrote:
> Dear all,
>
> In R-devel I have noticed the new approach for the "ts" class in the
> package "methods".
>
> the "structure" behaviour of "ts" is not always kept when one uses
> "ts" objects and objects of classes which extend the virtual class
> "structure".
>
> As a short example:
>
> ## this works fine
> setClass("foo", representation(header = "character"), contains = "structure")
> foo <- new("foo", 1:10, header = "foo")
> ts <- ts(1:10)
> foo / ts
>
> ## but the problem appears when one defines an "Ops" method for class "foo"
> setMethod("Ops", c("foo", "foo"),
> function(e1, e2) {
> .Data <- callGeneric(e1@.Data, e2@.Data)
> header <- paste(e1_at_header, e2_at_header, sep = "_")
> new("foo", .Data, header = header)
> })
> foo <- new("foo", 1:10, header = "foo")
> foo + foo
> ts <- ts(1:10)
> foo / ts
> # Error in getDataPart(1:10) : no '.Data' slot defined for class "ts"
>
> Is this the expected behavior?
>
No, not expected. It may take some special treatement to fix it, though.

Your subject heading is indeed the problem. Normally, the structure of an S3 class is a black box, and no S4 slots should usually be associated with it when it's registered via setOldClass.

However, just because "ts" does want to be a "structure" class, it would be nice to give it a .Data slot. I'll experiment with this and see if it causes other things to break immediately.

Thanks for the report.

John Chambers
> regards,
> Yohan
>
> --
> PhD student
> Swiss Federal Institute of Technology
> Zurich
>
> www.ethz.ch
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 07 Aug 2008 - 16:18:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Aug 2008 - 18:36:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive