Re: [Rd] self-referential representations in S4

From: John Chambers <>
Date: Wed, 20 Apr 2011 09:37:46 -0700

The warning is there because all is not "just fine", in general and in particular not in your example.

If a superclass is not virtual, the prototype object for the new class must have a member of that class in the appropriate slot. How could it do so in this case? As a result, your class will return an invalid object from a call to new().

So one might argue that the current rules are too lax, and this should be an error.

The fundamental point is that S4 classes, as opposed to the new reference classes, don't deal in "references", self- or other.

Ways to deal with such recursive structures are discussed in section 9.7 of Software for Data Analysis.

One version of what you were perhaps trying to do might, for a binary tree, be:

 > setClassUnion("MyNode", c("NULL", "vector")) [1] "MyNode"
 > setClass("FullNode", representation(left = "MyNode", right ="MyNode", + parent = "MyNode"))
[1] "FullNode"
 > setIs("FullNode", "MyNode")

Nodes can be full, a vector as a leaf, or empty.


On 4/19/11 3:10 PM, James Bullard wrote:
> I'm trying to do the following:
>> setClass("MyNode", representation(parent = "MyNode"))
> [1] "MyNode"
> Warning message:
> undefined slot classes in definition of "MyNode": parent(class "MyNode")
> I scanned the docs, but found nothing. The representation function has no
> problem, it's the setClass function which gives the warning.
> What I'm trying to understand is why have the warning - it seems to work
> just fine when I instantiate the class. Can we add an argument to the
> setClass to suppress the warning?
> This question was asked previously, but not answered in any satisfactory way:
> thanks, jim
> R version 2.12.2 Patched (2011-03-09 r54717)
> Platform: x86_64-unknown-linux-gnu (64-bit)
> locale:
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
> other attached packages:
> [1] h5r_1.1
> loaded via a namespace (and not attached):
> [1] tools_2.12.2
> ______________________________________________
> mailing list
> mailing list Received on Wed 20 Apr 2011 - 16:45:57 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 Wed 20 Apr 2011 - 17:20:51 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive