[R] Having problem to define a subclass, please help me

Megh Dal megh700004 at yahoo.com
Fri Jul 30 13:16:48 CEST 2010


Here I am having problem to define a subclass, specially if I define that subclass after defining initialize() method for its superclass. Here is my code:

> setClass("a", representation=list(x="numeric", y="numeric"), prototype=list(x=rnorm(10), y=rnorm(10)))
[1] "a"
> setMethod("initialize", "a", function(.Object, x, y, ...) {
+                                 if (length(x) != length(y)) x = y = rep(5, 4)
+                                 .Object at x = x
+                                 .Object at y = y
+                                 .Object })
[1] "initialize"
> setClass("b", representation=list(x1="character"), contains="a")
Error in .local(.Object, ...) : element 1 is empty;
   the part of the args list of 'length' being evaluated was:
   (x)
> 

Can anyone please point me where I am doing wrong?

Thanks,



More information about the R-help mailing list