[Bioc-devel] Why can't NAMESPACE be a strict subset of DESCRIPTION Imports?
Martin Morgan
martin.morgan at roswellpark.org
Wed Oct 5 20:30:00 CEST 2016
On 10/04/2016 05:09 PM, Martin Morgan wrote:
> On 10/04/2016 05:07 PM, McDavid, Andrew wrote:
>> BiocCheck throws a warning when a package is listed as Imports: in
>> DESCRIPTION but not used in the NAMESPACE. This may happen when a
>> developer uses the fully qualified names of objects within a package.
>> I am unclear as to the rationale for this warning.
>>
>
> agree it's wrong. can you point to an example? Martin
I updated BiocCheck to be smarter about this; I'm not sure when this
will propagate to the single package builder. It doesn't complain about
Imports: in the DESCRIPTION file if the package is used in the NAMESPACE
or :: or :::. The code is kind of fun, using the codetools package:
library(codetools)
.checkEnv <- function(env, walker) {
## look at all closures in 'env' using codetools-derived 'walker'
for (n in ls(env, all.names = TRUE)) {
v <- get(n, envir = env)
if (typeof(v) == "closure")
walkCode(body(v), walker)
}
walker
}
.colonWalker <- function() {
## record all pkg used as pkg::foo or pkg:::bar
PKGS <- character()
collector <- function(e, w)
PKGS <<- append(PKGS, as.character(e[[2]]))
list(handler=function(v, w) {
switch(v, "::"=collector, ":::"=collector, NULL)
}, call=function(e, w) {
for (ee in as.list(e)) if (!missing(ee)) walkCode(ee, w)
}, leaf = function(e, w) {
NULL
}, done = function() {
sort(unique(PKGS))
})
}
> library(codetools)
> .checkEnv(loadNamespace("IRanges"), .colonWalker())$done()
[1] "base" "BiocGenerics" "S4Vectors"
Martin
>
>> Per Hadley:
>>
>> It's common for packages to be listed in Imports in DESCRIPTION, but
>> not in NAMESPACE. In fact, this is what I recommend: list the package
>> in DESCRIPTION so that it's installed, then always refer to it
>> explicitly with pkg::fun(). Unless there is a strong reason not to,
>> it's better to be explicit. It's a little more work to write, but a
>> lot easier to read when you come back to the code in the future.
>>
>> Per R extensions:
>>
>> If a package only needs a few objects from another package it can use
>> a fully qualified variable reference in the code instead of a formal
>> import. A fully qualified reference to the function f in package foo
>> is of the form foo::f.
>>
>> -Andrew
>>
>>
>> [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> Bioc-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>>
>
>
> This email message may contain legally privileged and/or...{{dropped:2}}
>
> _______________________________________________
> Bioc-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel
This email message may contain legally privileged and/or...{{dropped:2}}
More information about the Bioc-devel
mailing list