[Rd] virtual superclasses

Bart kranstauber at orn.mpg.de
Tue May 29 23:37:55 CEST 2012


Dear List,

I'm exploring the use of class inheritance for a package were 
developing. I want to try to build on existing a class, i first want to 
extend this a bit using a virtual class and then extend this virtual 
class in multiple other classes. This would be similar to bar3 in the 
example below. Since there are nice functions for creating an object of 
the first superclass i would like to use that object for the 
initialization but somehow that fails with the error :"node stack 
overflow". How could i resolve this problem

Thanks in advance

Bart

 > setClass("foo", representation(a="numeric"),prototype = list( a = 
integer(0)))
 > setClass("bar", representation(b="numeric"))
 > setClass("foo2",contains=c("foo") )
 > setClass("foo3",contains=c("foo", "VIRTUAL") )
 > setClass("foo4",contains=c("foo", "bar") )
 > setClass("bar2",contains=c("foo2") )
 > setClass("bar3",contains=c("foo3") )
 > setClass("bar4",contains=c("foo4") )
 > i<-new("foo",a=1)
 > new("bar2", i)
An object of class "bar2"
Slot "a":
[1] 1

 > new("bar3", i)
Error in tryCatch(expr, error = function(e) { : node stack overflow
 > new("bar4", i)
An object of class "bar4"
Slot "a":
[1] 1

Slot "b":
numeric(0)
 > sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-pc-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=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=C                 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

loaded via a namespace (and not attached):
[1] tools_2.15.0



More information about the R-devel mailing list