From jmc at r-project.org  Wed May  8 18:02:11 2013
From: jmc at r-project.org (John Chambers)
Date: Wed, 08 May 2013 09:02:11 -0700
Subject: [Rd] Namespace/inheritance problem in S4 methods for a union
 class
In-Reply-To: <CAHavPHH2SWuCHPOz6O33KxUOjWbfGrBwfZ0-6dPn06uBydq3iA@mail.gmail.com>
References: <CAHavPHH2SWuCHPOz6O33KxUOjWbfGrBwfZ0-6dPn06uBydq3iA@mail.gmail.com>
Message-ID: <518A7703.3050004@r-project.org>

No need for generic functions and methods.  Just looking at the 
hierarchy of the classes shows the problem.

With Martin's simplified version:

 > library(PkgA)
 > extends("A")
[1] "A"
 > library(PkgB)
 > extends("B")
[1] "B" "A"
 > setClassUnion("C", c("matrix", "A"))
 > extends("A")
[1] "A" "C"
 > extends("B")
[1] "B" "A"


So defining the union does not make all the subclasses of "A" members of 
the union.

The next comments are guesses but plausible.  Loading the namespace of 
PkgB may not update the known subclasses of classes from PkgA.

This is one of R's touchier points in general:  The state of things with 
respect to classes and methods changes dynamically as packages are 
loaded.  Until PkgB is loaded, "A" has no known subclasses.

If the guess is correct, then when the  class union is formed, nothing 
tells us that "A" has a subclass "B" that should be added to the union.

Fixing this properly may involve the load-time actions and not be quite 
trivial.

John


On 5/7/13 11:05 PM, Renaud Gaujoux wrote:
> Hi,
>
> I started this post on bioc-devel but this seems to be more general:
>
> https://stat.ethz.ch/pipermail/bioc-devel/2013-May/004311.html
>
> See reproducible example from Martin below.
>
> Thank you.
>
> Renaud
>
> ---------- Forwarded message ----------
> From: Martin Morgan <mtmorgan at fhcrc.org>
> Date: 7 May 2013 19:55
> Subject: Re: [Bioc-devel] ExpressionSet and LumiBatch: inheritance problem
> in S4 methods for union class
> To: Renaud Gaujoux <renaud at mancala.cbio.uct.ac.za>
> Cc: bioc-devel at r-project.org, dupan.mail at gmail.com
>
> I can replicate this with a simpler example, where PkgA has
>
>    setClass("A", representation(x="numeric"))
>
> with NAMESPACE
>
>    import(methods)
>    exportClasses("A")
>
> PkgB has
>
>    setClass("B", contains="A")
>
> NAMESPACE
>
>    import(methods)
>    importClassesFrom("PkgA", "A")
>    exportClasses("B")
>
> and then
>
>    library(PkgA); library(PkgB)
>    setClassUnion("C", c("matrix", "A"))
>    setGeneric("do", function(x) standardGeneric("do"))
>    setMethod("do", "C", function(x) "done")
>
> leading to
>
>    > do(new("A"))
>    [1] "done"
>    > do(new("B"))
>
>    Error in (function (classes, fdef, mtable)  :
>      unable to find an inherited method for function ?do? for signature ?"B"?
>
> suggesting name space issues rather than something about ExpressionSet. The
> sample packages and test script are attached; it would be appropriate to
> pursue this on the R-devel mailing list.
>
> Martin
>
>
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] Namespace/inheritance problem in S4 methods for a union class
John Chambers