r package development imports not loaded

1.7k Views Asked by At

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?

1

There are 1 best solutions below

5
On BEST ANSWER

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)