r包开发导入未加载 [英] r package development imports not loaded

查看:233
本文介绍了r包开发导入未加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试通过以下方式导入依赖:

 导入:预测,ggplot2,dplyr 

当我点击Build&在Rstudio中重新加载我的库已经成功建成。但是,当检查依赖关系是否为真实的Rstudio加载时,告诉我们它们不是。
在我的命名空间文件中,我只有

  exportPattern(^ [[alpha:]] +)

是否有一个问题,没有具体导入命名空间,如 https://github.com/robjhyndman/forecast/blob/master/NAMESPACE



有什么问题?

解决方案

您需要将导入添加到 NAMESPACE 导入标签 DESCRIPTION 只列出了 NAMESPACE 中未列出的导入参考取决于标签。



导入从三个包中导出的所有内容您列出,添加以下内容到您的 NAMESPACE

  import(forecast, ggplot2,dplyr)

通常不建议从包中进行一次性导入。您应该选择性并仅导入您的软件包所需的功能。您可以通过 importFrom()



有关详细信息,请参阅第1.5.1节写入R扩展



可以使用 roxygen2 来管理这个,您可以通过 @import 标签(在#' roxygen注释中的R代码中,而不是 DESCRIPTION )。请参阅该软件包的文档和 Hadley Wickham的R软件包(在线版)


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. 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)

这篇关于r包开发导入未加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆