From ross at biostat.ucsf.edu  Thu Dec  3 23:59:29 2009
From: ross at biostat.ucsf.edu (Ross Boylan)
Date: Thu, 03 Dec 2009 14:59:29 -0800
Subject: [Rd] group generics
In-Reply-To: <4B183ACD.6000003@r-project.org>
References: <1259109265.8792.22.camel@markov.biostat.ucsf.edu>
	<6ph3a428z2r.fsf@gopher4.fhcrc.org> <4B144DC4.3020904@biostat.ucsf.edu>
	<4B1826EC.5090504@fhcrc.org>
	<1259876102.9331.1.camel@markov.biostat.ucsf.edu>
	<4B183ACD.6000003@r-project.org>
Message-ID: <1259881169.9331.15.camel@markov.biostat.ucsf.edu>

On Thu, 2009-12-03 at 14:25 -0800, John Chambers wrote:
> I missed the earlier round of this discussion and only am commenting
> now to say that this doesn't seem weird at all, if I understand what
> you're trying to do.
> 
> Martin's basic suggestion,
> v <- callGeneric(e1, as(e2, "A"))
> seems the simplest solution.
> 
> You just want to make another call to the actual generic function,
> with new arguments, and let method selection take place.  In fact,
> it's pretty much the standard way to use group generics.  
> 
> John
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
> 
> 
> Ross Boylan wrote: 
> > 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:
> >   
> > > setMethod("Arith", signature(e1="numeric", e2="B"), function(e1, e2) {
> > >     new("B", xb=e1*e2 at xb, callGeneric(e1, as(e2, "A")))
> > > })
> > >     
> > 
> > Things were getting too weird, so I punted and used explicitly named
> > function calls for the multiplication operation that was causing
> > trouble.
> > 
> > Ross
> > 
> > ______________________________________________
> > R-devel at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> > 
> >



[Rd] group generics
Ross Boylan