[Rd] Virtual class with no slots

From: Herve Pages <hpages_at_fhcrc.org>
Date: Wed, 26 Sep 2007 17:34:33 -0700


Hi,

It seems there are 2 slightly different ways to create a virtual class with no slots (a kind of Java "interface"): with or without specifying 'representation("VIRTUAL")'.

> setClass("A", representation("VIRTUAL"))
  [1] "A"

> showClass("A")

  Virtual Class

  No Slots, prototype of class "S4"

> setClass("B")

  [1] "B"

> showClass("B")

  Virtual Class

  No Slots, prototype of class "NULL"

Note that:

So my question is (just curiosity): why do we have 2 different forms (leading to different results) to create a virtual class with no slots. And which one is better?

Also note that, if I try to extend "A" without adding any new slot:

> setClass("AA", contains="A")

  [1] "AA"

> showClass("AA")

  No Slots, prototype of class "S4"

  Extends: "A"

now it seems that, yes, it is possible to create a non-virtual class with no slots! ( it's not easy though :-b ) So I'm wondering why this was not possible with 'setClass("B")' or 'setClass("B", representation())' in the first place.

Finally, if I try to instance "AA":

> new("AA")

  An object of class "AA"
  Error in getClass(class(object)) : "S4" is not a defined class

Oops! Seems that non-virtual classes with no slots are broken anyway :-/

Cheers,
H.

> sessionInfo()
R version 2.6.0 beta (2007-09-19 r42914) x86_64-unknown-linux-gnu

locale:
LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=en_US;LC_COLLATE=en_US;LC_MONETARY=en_US;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] rcompgen_0.1-15



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 27 Sep 2007 - 00:39:17 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 27 Sep 2007 - 00:42:33 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.