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:

  - R automatically decided to make B virtual, a strange design decision
    (IMO) that could have been motivated (I'm trying to guess here) by the
    fact that it is probably not very useful to create objects with no slots.
    But I would argue that it could also be left to the user to decide whether
    or not it is a good idea to create such objects (maybe s/he has a use case).

  - Surprisingly, A and B descriptions are slightly different: A's prototype
    is of class "S4" and B's prototype is of class "NULL".

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@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to