Hi I am new to writing R packages.
I try to import dependencies via:
Imports: forecast, ggplot2, dplyr
When I click Build & Reload in Rstudio my library is built successfully. However when checking if the dependencies are loaded for real Rstudio tells me that they are not. In my namespaces file I only have
exportPattern("^[[:alpha:]]+")
Is it a problem that there is no specific import of namespaces like in https://github.com/robjhyndman/forecast/blob/master/NAMESPACE
What is wrong?
You need to add the imports to the
NAMESPACE
. TheImports
tag inDESCRIPTION
just lists the packages that theNAMESPACE
references for imports that aren't listed in theDepends
tag.To import everything exported from the three packages you list, add the following to your
NAMESPACE
It is generally not advisable to just blanket import from packages. You should be selective and import only those functions that your package needs. You do that via
importFrom()
.For more details, see Section 1.5.1 in Writing R Extensions.
It might be worth using roxygen2 to manage this for you, which you do via the
@import
tag (in the R code in#'
roxygen comments, not inDESCRIPTION
). See the documentation for that package and Hadley Wickham's R Packages book (online version)