On Thu, Sep 17, 2009 at 5:59 PM, Martin Morgan <mtmor...@fhcrc.org> wrote:
> Gábor Csárdi wrote:
>> Dear All,
>>
>> maybe this is something obvious, I seem to be incapable of
>> understanding how S4 works.
>>
>> So, in package 'A' I defined a "summary" method for my class:
>>
>> setMethod("summary", signature(object="ListHyperGResult"),
>>           function(object, pvalue=pvalueCutoff(object), categorySize=NULL) {
>>              "whatever"
>>           })
>>
>> "ListHyperGResult" has a subclass, "GOListHyperGResult":
>>
>> setClass("GOListHyperGResult",
>>          representation=representation(conditional="logical"),
>>          contains="ListHyperGResult",
>>          prototype=prototype(testname="GO"))
>>
>> The summary method is exported in the NAMESPACE:
>>
>> exportMethods("summary")
>>
>> Package 'B' depends on package 'A', this is stated in the
>> 'DESCRIPTION' file. If I call 'summary' on a 'GOListHyperGResult' in
>
> Hi Gabor
>
> It is not S4 alone, but S4 + name spaces that are giving you problems.
>
> You probably want to Import: A rather than depends, and importFrom(A,
> summary).
>
> As it stands, inside the B name space, you find base::summary, whereas
> you've defined a method on summary that has been promoted to a generic
> in one of the packages that A imports (probably AnnotationDbi).
>
> This is a little bit of a guess; at some level it might seem more
> appropriate to Import: AnnotationDbi and importFrom(AnnotationDbi,
> summary) (or wherever the generic for summary that you are trying to use
> is created).

Martin, thanks, this solved the problem.

But isn't this a bit weird? Suppose I am the author of package 'B' and
want to use the classes defined in package 'A'. I don't care about
exact details of the implementation of these classes, I don't want to
know that they are based on something in package 'C' (AnnotationDbi,
really). But I still have to import specific functions from 'C'.

Moreover, suppose the author of 'C' changes 'summary', e.g. puts it
into another package, 'D' and makes 'C' importing it from 'D'. This
will break my package, 'B' as well.

Anyway, thanks a lot for your help, Best Regards,
Gabor

> Martin
>


-- 
Gabor Csardi <gabor.csa...@unil.ch>     UNIL DGM

______________________________________________
R-help@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.

Reply via email to