Folks,

My object oriented background is in Java and C++. I am a novice to using S4/object-oriented coding in R but not to R. Below is an example that I found that I have expanded on. 

I am not getting how "prototype" and "initialize" work together, if at all.

Here is output from a short "session"

> setClass("xx",
+          representation(a="numeric", b ="numeric"),
+          prototype(a=33, b = 333)
+ )
[1] "xx"
> 
> #setMethod("initialize", "xx", function(.Object){.Object})
> 
> setMethod("initialize", "xx", 
+           function(.Object, b) {
+             .Object@b<-b
+             .Object@a<-b^2
+             .Object
+           }
+ )
[1] "initialize"
> 
> new("xx", 3)
An object of class "xx"
Slot "a":
[1] 9

Slot "b":
[1] 3

> 
> new("xx")
Error in .local(.Object, ...) : argument "b" is missing, with no default

Any help you can provide would be greatly appreciated,
Thanks,
KW

--


	[[alternative HTML version deleted]]

