Reputation: 17676
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?
Upvotes: 0
Views: 1842
Reputation: 174778
You need to add the imports to the NAMESPACE
. The Imports
tag in DESCRIPTION
just lists the packages that the NAMESPACE
references for imports that aren't listed in the Depends
tag.
To import everything exported from the three packages you list, add the following to your NAMESPACE
import(forecast, ggplot2, dplyr)
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 in DESCRIPTION
). See the documentation for that package and Hadley Wickham's R Packages book (online version)
Upvotes: 3