[Bioc-devel] NAMESPACE question

Martin Morgan mtmorgan at fhcrc.org
Tue Oct 7 17:54:52 CEST 2014


On 10/07/2014 08:15 AM, Robert Castelo wrote:
> hi, it happens only with "[", that's why i'm puzzled.
>
> it behaves as if you load a GRanges object 'x' and try to subset it
>
> x[1]
>
> without loading 'GenomicRanges' first.

Is there a reproducible example? I see in your code there are several places 
where you require() or library() various packages. I think one of these 
Depends: on GenomicRanges, and the messages you see are the effect of moving 
GenomicRanges from 'loaded' to 'attached'. You can see the effect with

   library(qpgraph)
   sessionInfo()           ## GenomicRanges loaded but not attached
   library(GenomicRanges)  ## information about the package being attached

Probably in your code you do not actually want to require() ad hoc packages and 
influence the user search path (and implicitly rely on search path order for 
correct functionality), but rather to requireNamespace("foo"); foo::fun(...) (or 
possibly loadNamespace()).

Complicated!

Martin

>
> robert.
>
> On 10/07/2014 05:05 PM, Michael Lawrence wrote:
>> Does that happen with the other methods or just "["? As a last resort,
>> you could just drop the import (because "[" is a primitive, it should
>> just work).
>>
>> On Tue, Oct 7, 2014 at 3:08 AM, Robert Castelo <robert.castelo at upf.edu
>> <mailto:robert.castelo at upf.edu>> wrote:
>>
>>     hi Martin,
>>
>>     On 10/06/2014 07:24 PM, Martin Morgan wrote:
>>     [...]
>>
>>         There are two 'as.vector' generics, one defined in Matrix and one in
>>         BiocGenerics (and made available via IRanges). These generics have
>>         different methods
>>
>>          > showMethods(Matrix::as.vector)
>>         Function: as.vector (package base)
>>         x="abIndex", mode="ANY"
>>         x="abIndex", mode="character"
>>         x="ANY", mode="ANY"
>>         x="dgCMatrix", mode="missing"
>>         x="dgeMatrix", mode="missing"
>>         x="diagonalMatrix", mode="missing"
>>         x="dsCMatrix", mode="missing"
>>         x="ldenseMatrix", mode="missing"
>>         x="Matrix", mode="missing"
>>         x="ndenseMatrix", mode="missing"
>>         x="sparseVector", mode="character"
>>         x="sparseVector", mode="missing"
>>
>>          > showMethods(BiocGenerics::as.__vector)
>>         Function: as.vector (package BiocGenerics)
>>         x="ANY"
>>         x="AtomicList"
>>         x="Rle"
>>         x="XDouble"
>>         x="XInteger"
>>         x="XRaw"
>>         x="XString"
>>         x="XStringSet"
>>
>>         so it's important that your code clearly distinguish between
>>         generics.
>>         One possibility is to remove importMethodsFrom(IRanges,
>>         as.vector) from
>>         the NAMESPACE, and explicitly use IRanges::as.vector(...) in
>>         your code.
>>
>>
>>     ok, i've done this as it is the easiest at the moment to meet the
>>     release schedule. i guess that in the future i should try to avoid
>>     using the '::' operator by importing exclusively what is needed from
>>     each package.
>>
>>         codetoolsBioC::__writeNamespaceImports("__qpgraph") might
>>         provide you with
>>         some guidance (it's not 100% reliable; available via svn at
>>
>> https://hedgehog.fhcrc.org/__bioconductor/trunk/madman/__Rpacks/codetoolsBioC
>>
>> <https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/codetoolsBioC>)
>>         about what functionality is being imported.
>>
>>
>>     thanks for the heads up about codetoolsBioC, i've tried it out and
>>     seen that some of the suggested imports are not necessary but some
>>     others i was really missing them (which makes me wonder how was it
>>     possible that he package did not break at those points).
>>
>>     one further question related to NAMESPACE. i subset GRanges objects
>>     in the package via the '[' operator, i've included this into the
>>     NAMESPACE file as:
>>
>>     importMethodsFrom(__GenomicRanges,
>>                        c, cbind, rbind,
>>     "mcols<-", start, end, strand, sort,
>>     "[", "[<-", "[[", "[[<-", "$", "$<-")
>>
>>     however, when the package reaches a subset operation x[i] with x
>>     being a GRanges object, an entire package loading sequence starts:
>>
>>     Loading required package: GenomicRanges
>>     Loading required package: BiocGenerics
>>     Loading required package: parallel
>>
>>     Attaching package: ‘BiocGenerics’
>>     [... etc ...]
>>
>>     which may look a bit odd to the user. for every other imported
>>     method the package uses them silently without loading the
>>     corresponding package, am i importing '[' for GRanges objects from
>>     the wrong package? is there a way to import '[' so that my package
>>     can use it without triggering that package loading sequence?
>>
>>
>>     thanks again!
>>     robert.
>>
>>
>>     _________________________________________________
>>     Bioc-devel at r-project.org <mailto:Bioc-devel at r-project.org> mailing list
>>     https://stat.ethz.ch/mailman/__listinfo/bioc-devel
>>     <https://stat.ethz.ch/mailman/listinfo/bioc-devel>
>>
>>
>


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