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.
John
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:
>
> http://r.789695.n4.nabble.com/Linked-List-in-R-td3303021.html
>
> thanks, jim
>
>
>
>
> R version 2.12.2 Patched (2011-03-09 r54717)
> Platform: x86_64-unknown-linux-gnu (64-bit)
>
> locale:
> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
> [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8
> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
> [9] LC_ADDRESS=C LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> 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
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>