[R] identical function names from 2 packages

Duncan Murdoch murdoch.duncan at gmail.com
Thu May 19 13:56:37 CEST 2011


On 18/05/2011 10:02 PM, Nick Matzke wrote:
> Hi,
>
> If I load 2 packages that have a function with the same
> name, how do I tell R to run one or the other?
>
> (Instead of having R automatically use the first- or
> last-loaded one, whichever it is.  (Which is it, by the way.))
>
> Cheers!
> Nick
>
>

It is the most recently attached one that would be chosen by default. 
Generally that's also most recently loaded, but there can be exceptions.

Others have pointed out that :: is used to specify the package to use. 
If you use that, you don't need to have the package attached:  it will 
be loaded but won't show up in the search path.

If you are using a package without a namespace, expect problems.  Having 
the namespace is nearly as good as automatically adding the pkg:: prefix 
to every call from functions within the package.  Not having the 
namespace is nearly as bad as never using the prefix, even when you should.

Duncan Murdoch



More information about the R-help mailing list