[R] S4: Bug in group method defenition ("Compare")
Vitalie S.
vitosmail at rambler.ru
Mon Jun 15 19:54:16 CEST 2009
Dear UseRs,
Setting methods for groups ("compare" in this case) does not work
properly. Once one method is set ,redefining it or even removing does not
change the behavior:
setClass("foo"
,representation(range="numeric")
)
#[1] "foo"
setMethod("Compare",c(e1="ANY",e2="foo"),
function(e1,e2){
browser()
callGeneric(e1,e2 at range)
})
#[1] "Compare"
o<-new("foo",range=c(1,2))
2>o
#Called from: 2 > o
#Browse[1]>
#[1] TRUE FALSE ##Enters browser as expected !!!
# Now, remove browser()
setMethod("Compare",c(e1="ANY",e2="foo"),
function(e1,e2){
callGeneric(e1,e2 at range)
})
2>o
#Called from: 2 > o
#Browse[1]> ######## Oups, the old function is executed here?????????
########
#[1] TRUE FALSE
selectMethod(">=",c(class(2),class(o)),optional=T) ### Shows real
method!!!!!
#function (e1, e2)
#{
# callGeneric(e1, e2 at range)
#}
#
#Signatures:
# e1 e2
#target "numeric" "foo"
#defined "ANY" "foo"
removeMethod("Compare",c(e1="ANY",e2="foo"))
#[1] TRUE
2>o
##Called from: 2 > o ### What?? Even after removing method the first
defined
### method is still there!!!!
#Browse[1]>
#[1] TRUE FALSE
I tried this under Windows Xp in 2.8 and 2.9.0.
Vitalie.
More information about the R-help
mailing list