[Rd] "Incompatible methods" for overloaded operator

Renaud Gaujoux renaud at mancala.cbio.uct.ac.za
Thu Jun 21 13:22:01 CEST 2012


Hi,

I may be mistaken here but a possible interpretation of:

"If a method is found for just one argument or the same method is found 
for both, it is used."

could be that "the same method" here does not mean identical in term of 
object/content (as identical tests), but means that the two arguments 
resolve to the same method definition, i.e. a single common method 
exists for both arguments. This would happen is if a single method is  
defined for a common parent class. Try:


`+.C` <- function(x1, x2){
     message("Running custom + function")
}

x <- structure(1, class=c('A', 'C'))
y <- structure(1, class=c('B', 'C'))

x + y


Another work around would be to define only one method for class 'a' and 
do the dispatch to `plus.b` in there (might even be able to call it 
`+.b` if not exported).

Might be a good suggestion to add a test in UseMethod to check is the 
methods are in fact identical. But there might be undesired side 
effects: two identical methods in different environment that behave 
differently depending on the state of the environment?
By the way any way of seeing any code of primitive function or are these 
pure C functions, which need to be searched for in R source code?

Renaud

-- 
Renaud Gaujoux
Computational Biology - University of Cape Town
South Africa



More information about the R-devel mailing list