[Bioc-devel] Nasty function collision
Robert Gentleman
rgentlem at fhcrc.org
Tue Oct 31 19:02:23 CET 2006
That is IMHO pretty much it - not a problem, and why namespaces exist.
I really think that you want to use iii) in preference to either i) or
ii), and if you only want that getURL then I would import it with that name.
Seth Falcon wrote:
> "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. :-)
>
> Best,
>
> + seth
>
> _______________________________________________
> Bioc-devel at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>
--
Robert Gentleman, PhD
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
PO Box 19024
Seattle, Washington 98109-1024
206-667-7700
rgentlem at fhcrc.org
More information about the Bioc-devel
mailing list