r package development imports not loaded

好久不见. 提交于 2019-12-08 09:12:57

问题


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:


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)



来源:https://stackoverflow.com/questions/30719243/r-package-development-imports-not-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!