[R] callNextMethod & initialize & explicit parameters
laurent buffat
laurent.buffat at it-omics.com
Mon May 26 18:31:37 CEST 2003
Hello,
I know that in general, it is better to call callNextMethod without
arguments,
and so the call is done with the current arguments, but I want explicitly
change the value of
a given argument, how can I do ?
See the code. Why is doesn't work ?
Thanks for your help
Laurent Buffat
///////////////////////
setClass("A", representation(a = "numeric"))
setMethod("initialize", "A", function(.Object, a=1, ...)
cat("initialize in A\n")
.Object at a <- a
return(.Object)
})
setClass("B", representation(b = "numeric"),contains=c("A"))
setMethod("initialize", "B", function(.Object, a=1, b=2, ...)
{
a.init <- b*b # or something more complexe ...
.Object <- callNextMethod(.Object,a=a.init, ...)
.Object at b <- b
return(.Object)
})
x <-new("B")
/////////////////// error with new("B").
# The evaluation of "a=a.init" is done in the environment of initialize,A,
and a.init doesn't exist
# in this environment ...
initialize in A
Error in .local(.Object, ...) : Object "a.init" not found
More information about the R-help
mailing list