Re: [R] inheritence in S4

From: Martin Morgan <mtmorgan_at_fhcrc.org>
Date: Sat, 01 Mar 2008 06:03:49 -0800

Hi Christophe --

I don't know whether there's a particularly elegant way. This works

setClass("A", representation(x="numeric"))
setClass("B", representation(y="numeric"))
setClass("C", contains=c("A", "B"))

setMethod("show", "A", function(object) cat("A\n"))
setMethod("show", "B", function(object) cat("B\n")) setMethod("show", "C", function(object) {

    callGeneric(as(object, "A"))
    callGeneric(as(object, "B"))
    cat("C\n")
})

> new("C")

A
B
C

but obviously involves the developer in making explicit decisions about method dispatch when there is multiple inheritance.

Martin

cgenolin_at_u-paris10.fr writes:

> Hi the list
>
> I define a class A (slot a and b), a class C (slot c and d) and a class
> E that inherit from A and B.
> I define print(A) and print(B). For print(C), I would like to use both
> of them, but I do not see how...
>
> Thanks for your help...
>
> Christophe
>
> ----------------------------------------------------------------
> Ce message a ete envoye par IMP, grace a l'Universite Paris 10 Nanterre
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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

Location: Arnold Building M2 B169
Phone: (206) 667-2793

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 01 Mar 2008 - 14:12:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 24 Mar 2008 - 10:30:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive