[R] S4: Initialization method called during setClass??

Vitalie S. vitosmail at rambler.ru
Fri Jun 5 18:28:56 CEST 2009


Dear UseRs,

A simple class inheritance example:

> setClass("test",representation(a="numeric"))
> setMethod("initialize","test",
           function(.Object,x,...){
               print("Initialization!!!")
               callNextMethod(.Object,a=x,...)
           })

> new("test",x=23)
[1] "Initialization!!!"
An object of class "test"
Slot "a":
[1] 23

> setClass("test2",contains="test",representation(b="integer"))
[1] "Initialization!!!"
Error in .nextMethod(.Object, a = x, ...) : 
  argument "x" is missing, with no default


When trying to define a new class "test2" above, "initialize" method for "test" is called (??? looks like a bug to me) and naturally argument "x" is not found. Thus I can not create a subclass for "test". 

I could not find anything in documentation. 

Thanks,
Vitalie.




More information about the R-help mailing list