Parlamis Franklin
2006-Oct-20 09:24 UTC
[Rd] understanding virtual classes and extensions thereof
I am having some trouble creating a hierarchy of virtual classes
(akin to the class structure in the 'Matrix' package). I think they
arise from my not understanding the best way to specify virtual
subclasses of a virtual class. please see questions below code.
setClass("mom")
setClass("kid1", representation("mom", "VIRTUAL"))
setClass("kid2", representation("VIRTUAL"), contains =
"mom")
setClass("kid3"); setIs("kid3", "mom")
(i) Are 'kid1' and 'kid2' equivalent? I.e., is there any
difference
between including a superclass as an unnamed argument in the
'representation' call and including it in the 'contains'
argument?
If not, why does the 'contains' argument exist?
(ii) What is the difference between 'kid1' and 'kid2', on the
one
hand, and 'kid3', on the other hand? I see that 'kid1' and
'kid2'
have prototypes of class 'S4', while 'kid3' has a prototype of
class
"NULL". But I don't really understand the implications of that.
I
am using virtual classes mostly to economize on method writing. Will
it matter on any level whether my virtual classes have NULL or S4
prototypes?
On a related note, the behavior exhibited below also seems infelicitous
setClass("kid4", contains = "mom")
new("kid4") # error in the show method
franklin parlamis
John Chambers
2006-Oct-21 14:43 UTC
[Rd] understanding virtual classes and extensions thereof
IMO, the recommended version is:
setClass("kid2", contains = c("mom", "VIRTUAL"))
because it's the clearest, using the representation argument only for
defining slots. Better yet, if your virtual classes don't have any
slots defined, use setClassUnion() for "mom", with the other classes
members of the union.
The other versions are mainly to be back-compatible, with "Programming
with Data" in particular. They _should_ produce the same result.
As for:
setClass("kid4", contains = "mom")
this is currently a meaningless class: It's not virtual but it has no
meaningful prototype. My preference would be a change that makes this a
virtual class, as the programmer probably intended (maybe with a warning
for now since it's technically a change in the API).
Parlamis Franklin wrote:> I am having some trouble creating a hierarchy of virtual classes
> (akin to the class structure in the 'Matrix' package). I think
they
> arise from my not understanding the best way to specify virtual
> subclasses of a virtual class. please see questions below code.
>
> setClass("mom")
>
> setClass("kid1", representation("mom",
"VIRTUAL"))
> setClass("kid2", representation("VIRTUAL"), contains =
"mom")
> setClass("kid3"); setIs("kid3", "mom")
>
> (i) Are 'kid1' and 'kid2' equivalent? I.e., is there any
difference
> between including a superclass as an unnamed argument in the
> 'representation' call and including it in the 'contains'
argument?
> If not, why does the 'contains' argument exist?
>
> (ii) What is the difference between 'kid1' and 'kid2', on
the one
> hand, and 'kid3', on the other hand? I see that 'kid1' and
'kid2'
> have prototypes of class 'S4', while 'kid3' has a prototype
of class
> "NULL". But I don't really understand the implications of
that. I
> am using virtual classes mostly to economize on method writing. Will
> it matter on any level whether my virtual classes have NULL or S4
> prototypes?
>
> On a related note, the behavior exhibited below also seems infelicitous
>
> setClass("kid4", contains = "mom")
> new("kid4") # error in the show method
>
> franklin parlamis
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>