Re: [Rd] group generics

From: Martin Morgan <mtmorgan_at_fhcrc.org>
Date: Wed, 25 Nov 2009 06:21:32 -0800

Hi Ross --

Ross Boylan <ross_at_biostat.ucsf.edu> writes:

> I have classes A and B, where B contains A. In the implementation of
> the group generic for B I would like to use the corresponding group
> generic for A. Is there a way to do that?
>
> I would also appreciate any comments if what I'm trying to do seems like
> the wrong approach.
>
> Here's a stripped down example:
> setClass("A",
> representation=representation(xa="numeric")
> )
>
> setMethod("Arith", signature(e1="numeric", e2="A"), function(e1, e2) {
> new("A", ax=e1*e2_at_xa)

typo, I guess, xa = e1...

> }
> )
>
> setClass("B",
> representation=representation(xb="numeric"),
> contains=c("A")
> )
>
> setMethod("Arith", signature(e1="numeric", e2="B"), function(e1, e2) {
> # the next line does not work right
> v <- selectMethod("callGeneric", signature=c("numeric", "A"))(e1, e2)

    v <- callGeneric(e1, as(e2, "A"))

or probably

   v <- callNextMethod(e1, e2)

Martin

> print(v)
> new("B", v, xb=e1*e2_at_xb)
> }
> )
>
>
> Results:
>> t1 <- new("B", new("A", xa=4), xb=2)
>> t1
> An object of class B
> Slot "xb":
> [1] 2
>
> Slot "xa":
> [1] 4
>
>> 3*t1
> Error in getGeneric(f, !optional) :
> no generic function found for "callGeneric"
>
> Thanks.
> Ross Boylan
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Martin Morgan
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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 25 Nov 2009 - 14:24:17 GMT

This archive was generated by hypermail 2.2.0 : Tue 01 Dec 2009 - 01:30:53 GMT