Consider a simple R function:
#' @importFrom BarPackage Bar
Foo <- function (n, x) {
replicate(1e6, Bar(numeric(n), x))
}
If Bar()
is a method, then calling Bar.numeric(numeric(n), x)
saves R from having to look up the class of numeric(n)
; in a real-world example, this shaves about 10% off my run time.
However, Bar.numeric()
is a function in a separate package (which I maintain). Roxygen creates export(Bar)
and S3method(Bar, numeric)
entries in NAMESPACE, but if I add importFrom BarPackage Bar
to the FooPackage NAMESPACE and try to run Foo()
, I see Warning message: 'Bar.numeric' is not exported by 'namespace:BarPackage'
-- as indeed it's not.
It feels like I need to create a separate entry in my NAMESPACE reading export(Bar.numeric)
, but this feels like a very bad idea (in part because I don't think that Roxygen will do it). Is there any other way of avoiding R having to look up the class of numeric(n)
on each call to Bar()
?