[Bioc-devel] Nasty function collision

Seth Falcon sfalcon at fhcrc.org
Tue Oct 31 18:27:55 CET 2006

"James MacDonald" <jmacdon at med.umich.edu> writes:
> I am having a nasty function collision in my affycoretools package
> that is causing things to error out.  I have tracked the problem
> down to the getURL() functions that are defined in RCurl and
> annaffy. If I load RCurl first and then annaffy, getURL() is
> silently masked, probably because it is an S4 function in annaffy
> and a regular function in RCurl.

Since annaffy has a NAMESPACE, this is easy to resolve.  You can:

i) Make calls to annaffy::getURL where appropriate

ii) "Rename" annaffy's getURL function in your package code:

        annaffy_getURL <- annaffy::getURL

iii) Rename annaffy's getURL at import time:

       importFrom("annaffy", foo=getURL)

IMO, this sort of conflict is really not nasty at all.  What would be
nasty is to expect package developers to keep in mind the global name
space consisting of the union of all existing packages and to name
their functions accordingly.  

> If I do the opposite, R is nice enough to mention that I have just
> masked a function from annaffy. 

Seems odd that you only sometimes get a warning since both packages
have a name space.  But perhaps it depends on details of
import/require/depend, etc.

> In the past I got around this problem by importing annaffy rather than
> listing it in the Depends line in the DESCRIPTION file, and load()ing it
> when needed. This worked out OK because one is likely to be using either
> annaffy to create output, or biomaRt, but not usually both, so the
> masking problem was a moot point. Having annaffy in Imports ensured that
> things like biocLite() would automatically install it as a
> dependency.

Listing it in Imports in DESCRIPTION implies you really import it in
the NAMESPACE file -- and that means it gets loaded (but not attached
to the search path).

> Unfortunately now R CMD check complains about "'library' or 'require'
> calls not declared from: annaffy" and points me to Creating R Packages
> and the DESCRIPTION file entry, which doesn't really enlighten.

Separate issue which might have a reasonable workaround, but I think
you want i, ii, or iii above. :-)


+ seth

More information about the Bioc-devel mailing list