[R] Risks of using "function <- package::function" ?
jdnewmil at dcn.davis.ca.us
Fri Nov 17 08:30:40 CET 2017
Obvious? How about "obscurity"? Just directly use pkg::fun if you have name collision.
Sent from my phone. Please excuse my brevity.
On November 16, 2017 4:46:15 PM PST, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>On 16/11/2017 4:53 PM, Boris Steipe wrote:
>> Large packages sometimes mask each other's functions and that creates
>a headache, especially for teaching code, since function signatures may
>depend on which order packages were loaded in. One of my students
>proposed using the idiom
>> <function> <- <package>::<function>
>> ... in a preamble, when we use just a small subset of functions from
>a larger package. I like that idea and can't see obvious
>> Are there subtle risks to that approach?
>You might do it twice. R isn't going to complain if you have
>filter <- stats::filter
># some other code here...
>filter <- dplyr::filter
>in your code, but the second one will overwrite the first one.
>The normal way to handle this is in the NAMESPACE file, where you
>If you then have
>you should get an warning:
>Warning: replacing previous import ‘stats::filter’ by ‘dplyr::filter’
>when loading ‘testpkg’.
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help