From mtmorgan at fhcrc.org  Thu Jun 21 05:49:13 2012
From: mtmorgan at fhcrc.org (Martin Morgan)
Date: Wed, 20 Jun 2012 20:49:13 -0700
Subject: [Rd] "Incompatible methods" for overloaded operator
In-Reply-To: <CABdHhvGKRgTTSJRQUS3pu_GDLTJkk0HBTpinHvFTJn1zA7E+qA@mail.gmail.com>
References: <CAFOpNVFyqaTZHG15N2w13OqBJSwdVfdpbWGfsJim3XhNCmdYfw@mail.gmail.com>
	<CABdHhvF-WRwa9QaXG7Tb6JoiZJYH70OzUSdvAwUSY_6ZTnWvHQ@mail.gmail.com>
	<4FE28E2D.7050205@fhcrc.org>
	<CABdHhvGKRgTTSJRQUS3pu_GDLTJkk0HBTpinHvFTJn1zA7E+qA@mail.gmail.com>
Message-ID: <4FE299B9.2080400@fhcrc.org>

On 06/20/2012 08:06 PM, Hadley Wickham wrote:
>> from ?groupGeneric under 'Ops' (of which "+" is one)
>>
>>           used.  If different methods are found, there is a warning
>>           about 'incompatible methods': in that case or if no method is
>>           found for either argument the internal method is used.
>>
>> which doesn't really explain why it works at the command line but not in a
>> package. S4 methods can be defined on both arguments, so
>
> But aren't the methods compatible?  If equality doesn't make a method
> compatible what does?

Actually I guess that turns out to be the key (to why they work at the 
command line but not in a package).  At the command line they really 
_are_ the same, e.g., .Internal(inspect("+.a")) has the same  address as 
"+.b". In the package they (e.g., badadd:::"+.a") have different 
addresses, I suppose because S3method() acts on them independently.

>
>>   setClass("A", contains="numeric")
>>   setClass("B", contains="numeric")
>>
>>   setMethod("+", c("A", "A"), function(e1, e2) message("A + A"))
>>   setMethod("+", c("A", "B"), function(e1, e2) message("A + B"))
>>   setMethod("+", c("B", "A"), function(e1, e2) message("B + A"))
>>   setMethod("+", c("B", "B"), function(e1, e2) message("B + B"))
>>
>> with
>>
>>   exportClasses("A", "B")
>>   exportMethods("+")
>>
>> and then
>>
>>> new("A") + new("B")
>> A + B
>> NULL
>
> But unfortunately that doesn't work for S3 classes (even with
> setOldClass) so it doesn't help much unless we want to rewrite
> everything in S4 :/

rewrite?

>
> Hadley
>


-- 
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793



[Rd] "Incompatible methods" for overloaded operator
Martin Morgan