[R] modify the imported version of a function
Benjamin Tyner
btyner at gmail.com
Sat Dec 17 00:06:12 CET 2016
Hi
I saw on the assignInNamespace help page, that it changes "the copy in
the namespace, but not any copies already exported from the namespace,
in particular an object of that name in the package (if already
attached) and any copies already imported into other namespaces."
So now I'm wondering, whether there is a way to modify such copies
already imported into other namespaces? For a concrete example, consider
the lint package (now archived on CRAN) which includes a function
check_pattern, which calls stringr:::perl, which has been deprecated in
newer versions:
> stringr:::perl
function (pattern)
{
message("perl is deprecated. Please use regexp instead")
regex(pattern)
}
<environment: namespace:stringr>
so, what if I wanted to directly replace stringr:::perl with
stringr:::regex, in such a way that lint::check_pattern sees the
replacement? Is there a way, preferably without having to attach stringr
to the search path?
(I'm mostly just interested in learning about how namespace imports
actually work; of course in this toy example one could use
suppressMessages to hide that deprecation message).
Regards
Ben
More information about the R-help
mailing list