[Bioc-devel] NAMESPACE issue, possibly related to AnnotationDbi

Martin Morgan mtmorgan at fhcrc.org
Fri Dec 4 18:34:42 CET 2009


Hi Jelle --

J.J.Goeman at lumc.nl wrote:
>  Dear all,
> 
> I ran into a NAMESPACE problem, which I solved (more or less) but which
> I still want to share, because I do not completely understand what is
> happening.
> 
> On Rcmd check, my package vignette gave the error
> 
> Error in as.list.default(alias) : 
>   no method for coercing this S4 class to a vector
> 
> The culprit was a call of as.list(alias), where alias = hu6800SYMBOL,
> inside a function. Similar errors arose using mget on hu6800SYMBOL.
> 
> As the vignette ran without errors if I just sourced all my R files, I
> concluded it must be a namespace problem. I INSTALLed my package with a
> browser() in the right location, and I was able to produce the following
> output:
> 
>> features(res, alias=hu6800SYMBOL)
> Called from: covariates(...)
> Browse[1]> class(alias)
> [1] "ProbeAnnDbBimap"
> attr(,"package")
> [1] "AnnotationDbi"
> Browse[1]> showMethods("as.list")
> Function: as.list (package base)
> x="AgiAnnDbMap"
> x="AnnDbBimap"
> x="ANY"
> x="Bimap"
> x="EBMTP"
> x="FlatBimap"
>     (inherited from: x="Bimap")
> x="GoAnnDbBimap"
> x="GOTermsAnnDbBimap"
> x="IpiAnnDbMap"
> x="logical"
>     (inherited from: x="ANY")
> x="MTP"
> x="ProbeAnnDbBimap"
>     (inherited from: x="AnnDbBimap")
> Browse[1]> as.list(alias)
> Error in as.list.default(alias) : 
>   no method for coercing this S4 class to a vector
> 
> Clearly, AnnotationDbi is attached, but somehow as.list() is not able to
> find the method for the ProbeAnnDbBimap object that is inherited from
> AnnDbBimap.
> 
> As I had already concluded that it was a namespace problem, I tried
> adding 
> 
> importFrom(AnnotationDbi, as.list)
> 
> to my NAMESPACE file. That solved the error (or worked around it?), but
> I don't really understand why.

AnnotationDbi promotes as.list to an S4 generic. Without the import,
your package finds base::as.list, which knows nothing of the generic
(and methods associated with it). This is analogous to the situation
with a regular function.

There might be some additional complexity with the showMethods output.
Consistent with my understanding, if in a new R session I

library(Biobase)
library(AnnotationDbi)
data(sample.ExpressionSet)
trace(pData, browser) # I'll be inside the Biobase name space

I get

> showMethods(as.list)
Function: as.list (package base)
x="AgiAnnDbMap"
x="AnnDbBimap"
x="ANY"
x="Bimap"
x="GoAnnDbBimap"
x="GOTermsAnnDbBimap"
x="IpiAnnDbMap"

> pData(sample.ExpressionSet)
Tracing pData(phenoData(object)) on entry
Called from: eval(expr, envir, enclos)
Browse[1]> showMethods(as.list)

Function "as.list":
 <not a generic function>

There does seem to be a glitch here, though, because forcing name
resolution rather than symbol look up results in

Browse[1]> showMethods("as.list")
Function: as.list (package base)
x="AgiAnnDbMap"
x="AnnDbBimap"
x="ANY"
x="Bimap"
x="GoAnnDbBimap"
x="GOTermsAnnDbBimap"
x="IpiAnnDbMap"

I guess logically this is making some sense -- as.list is not a generic,
whereas showMethods("as.list") says explicitly to look for the methods
on the as.list generic, and since base::as.list is not a generic the
search continues until AnnotationDbi::as.list is encountered.

Martin

> 
> I'd be grateful if somebody who knows more about namespaces could
> explain this issue to me.
> 
> Session info below.
> 
> Jelle
> 
> 
> R version 2.10.0 (2009-10-26) 
> i386-pc-mingw32 
> 
> locale:
> [1] LC_COLLATE=English_United Kingdom.1252 
> [2] LC_CTYPE=English_United Kingdom.1252   
> [3] LC_MONETARY=English_United Kingdom.1252
> [4] LC_NUMERIC=C                           
> [5] LC_TIME=English_United Kingdom.1252    
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> 
> 
> other attached packages:
>  [1] annotate_1.24.0     KEGG.db_2.3.5       hu6800.db_2.3.5    
>  [4] org.Hs.eg.db_2.3.6  RSQLite_0.7-3       DBI_0.2-4          
>  [7] AnnotationDbi_1.8.1 vsn_3.14.0          golubEsets_1.4.7   
> [10] globaltest_5.1.1    Biobase_2.5.8      
> 
> loaded via a namespace (and not attached):
>  [1] affy_1.24.2          affyio_1.14.0        grid_2.10.0         
>  [4] lattice_0.17-26      limma_2.19.1         MASS_7.3-4          
>  [7] multtest_2.2.0       preprocessCore_1.7.4 splines_2.10.0      
> [10] survival_2.35-7      tools_2.10.0         xtable_1.5-6 
> 
> www.msbi.nl/goeman 
> 
> _______________________________________________
> Bioc-devel at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-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



More information about the Bioc-devel mailing list