简体   繁体   English

r包开发导入未加载

[英]r package development imports not loaded

Hi I am new to writing R packages. 嗨,我是刚开始写R包。

I try to import dependencies via: 我尝试通过以下方式导入依赖项:

Imports: forecast, ggplot2, dplyr

When I click Build & Reload in Rstudio my library is built successfully. 当我单击Rstudio中的“构建并重新加载”时,我的库已成功构建。 However when checking if the dependencies are loaded for real Rstudio tells me that they are not. 但是,当检查是否为真实的Rstudio加载了依赖项时,告诉我它们不是。 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 是否没有像https://github.com/robjhyndman/forecast/blob/master/NAMESPACE这样的名称空间没有特定的导入的问题

What is wrong? 怎么了?

You need to add the imports to the NAMESPACE . 您需要将导入添加到NAMESPACE The Imports tag in DESCRIPTION just lists the packages that the NAMESPACE references for imports that aren't listed in the Depends tag. DESCRIPTIONImports标记仅列出NAMESPACE引用的软件包,这些软件包未在Depends标记中列出。

To import everything exported from the three packages you list, add the following to your NAMESPACE 要导入从您列出的三个软件包中导出的所有内容,请在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() . 您可以通过importFrom()

For more details, see Section 1.5.1 in Writing R Extensions . 有关更多详细信息,请参见“编写R扩展”中的1.5.1节

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 ). 可能值得使用roxygen2为您管理此操作,您可以通过@import标记(在#' roxygen注释中的R代码中,而不在DESCRIPTION )进行此操作。 See the documentation for that package and Hadley Wickham's R Packages book (online version) 请参阅该软件包的文档和Hadley Wickham的R软件包一书(在线版本)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM