Hi Vitalie --

Vitalie S. wrote:
> 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

the implicit contract is that the initialize method is written so that
new("test") works. This contract comes up at several points during class
definition and instantiation. You've identified one of those points.

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

I'm not sure of the details, but part of the class definition is a
coercion method, and in defining this new() is called, without
arguments, on the contained classes.

Martin

> 
> 
> 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.
> 
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to