[R] S4 Method Dispatch for Sealed Classes
Thomas Koenig
thomas.koenig at epigenomics.com
Thu Aug 31 18:36:57 CEST 2006
Hi,
I encounter a problem with method dispatch with S4 classes, using the
'sealed' parameter in setClass.
See that example below:
setClass("X",representation(x="numeric"),sealed=TRUE)
setGeneric("foo",function(x) standardGeneric("foo"))
setMethod("foo",signature("X"),function(x) print("foo(X)"))
x <- new("X")
foo(x) ## works fine
setClass("Y",representation("X"))
y <- new("Y")
foo(y) ## works fine
setClass("Z",representation("X"),sealed=TRUE)
z <- new("Z")
extends("Z")
## [1] "Z" "X"
foo(z) ## error
Error in foo(z) : no direct or inherited method for function 'foo' for
this call
My question is: why does sealed=TRUE impact on method dispatch?
Please, can you point me to the relevant documentation?
Reading ?setMethod, ?Methods, I failed to find an answer.
Thank you.
Best.
Thomas
Tried on R 2.3.1 and R 2.4.0-devel (2006-08-29 r39012): same result.
--
Thomas Koenig Biostatistician
Epigenomics AG Kleine Praesidentenstr. 1 10178 Berlin, Germany
phone:+49-30-24345-376 fax:+49-30-24345-555
http://www.epigenomics.com thomas.koenig at epigenomics.com
More information about the R-help
mailing list