I am writing a R package and I want to import generic function forecast
from the package forecast. My package provides the method forecast.myobj
. I have the forecast
in the Imports:
in the package DESCRIPTION
file and my function definition is as following:
##' @export
forecast.myobj <- function(x) {
}
I am using devtools package (version 1.5) to build the package. The generated NAMESPACE
has the following
S3method(forecast, myobj)
importFrom(forecast, forecast)
However when I load my package in a clean R session, function forecast
is not available. Interestingly though I can see help pages of forecast
and forecast.myobj
and I can access these functions via forecast::forecast
and mypackage:::forecast.myobj
. Is it possible somehow to make forecast
available to the user without depending on the package forecast
? I checked documentation and reviewed a bunch of similar questions here, but I did not find the definite negative or positive answer.
import: An Import Mechanism for R The syntax allows for importing multiple objects from a package with a single command in an expressive way. The import package bridges some of the gap between using library (or require ) and direct (single-object) imports.
The imported function must be exported in the NAMESPACE file for it to be available to users:
S3method(forecat, myobj)
importFrom(forecast, forecast)
export(forecast)
For an example, see the dplyr package's NAMESPACE file which imports %>%
from the magrittr package and exports it so that it is accessible by the user.
Giving my own answer to add information how to achieve the NAMESPACE
described in @G. Grothendieck's answer using devtools package. The following lines (modeled after dplyr's code) do the trick
##' @importFrom forecast forecast
##' @name forecast
##' @rdname forecast.myobj
##' @export
NULL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With