Skip to content

group generics

4 messages · Martin Morgan, Ross Boylan, John Chambers

#
Hi Ross --
Ross Boylan wrote:
I feel obliged to respond, since you were following my original
suggestion, but I don't really have a clear answer. I think the error
message is really an issue in the S4 infrastructure, arising from
combining callNextMethod, callGeneric, and group generics; I don't have
further insight on solving the underlying problem, and perhaps I have
misplaced expectations on how these elements are supposed to play
together. A work around is to stick with callGeneric

setClass("A", representation=representation(xa="numeric"))

setMethod("Arith", signature(e1="numeric", e2="A"), function(e1, e2) {
    new("A", xa=callGeneric(e1, e2 at xa))
})

setClass("B",
         representation=representation(xb="numeric"),
         contains=c("A"))

setMethod("Arith", signature(e1="numeric", e2="B"), function(e1, e2) {
    new("B", xb=e1*e2 at xb, callGeneric(e1, as(e2, "A")))
})

tb <- new("B", xb=1:3, new("A", xa=10)); 3 * tb

Martin

  
    
#
Thanks for your help.  I had two concerns about using as: that it would
impose some overhead, and that it would require me to code an explicit
conversion function.  I see now that the latter is not true; I don't
know if the overhead makes much difference.
On Thu, 2009-12-03 at 13:00 -0800, Martin Morgan wrote:
Things were getting too weird, so I punted and used explicitly named
function calls for the multiplication operation that was causing
trouble.

Ross
#
On Thu, 2009-12-03 at 14:25 -0800, John Chambers wrote:
There were 2 weird parts.  Mainly I was referring to the fact that
identical code (posted earlier) worked sometimes and not others.  I
could not figure out what the differences were between the 2 scenarios,
nor could I create a non-working scenario reliably.

The second part that seemed weird was that the code looked as if it
should work all the time (the last full version I posted, which used
callNextMethod() rather than callGeneric()).

Finally, I felt somewhat at sea with the group generics, since I wasn't
sure exactly how they worked, how they interacted with primitives, or
how they interacted with callNextMethod, selectMethod, etc.  I did study
what I thought were the relevant help entries.

Ross