【问题标题】:Import doesn't import in r package development导入不会在 r 包开发中导入
【发布时间】:2017-10-07 13:11:44
【问题描述】:

我正在尝试创建一个包。我将ggplot2 库用于其中一个功能。

我已经为函数编写了导入语句:

#' @param x the dataframe
#' @param Column the dataframe
#' @param Code the dataframe
#' @keywords Appointment filtering
#' @import ggplot2
#' @importFrom magrittr '%>%'
#' @importFrom dplyr arrange group_by summarise
#' @import rlang
#' @export

并将Imports:ggplot2 写在DESCRIPTION 中,如下所示

Package: MyPackage
Title: What the Package Does (one line, title case)
Version: 0.0.0.9000
Authors@R: person("Sebastian", "Zeki", email = "first.last@example.com", role = c("aut", "cre"))
Description: What the package does (one paragraph).
Depends: R (>= 3.4.0)
Imports:
    ggplot2
License: What license is it under?
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1

每当我从 devtools 运行 load_all()document() 时,我都会收到错误消息:

Error in ggplot(....) : 
  could not find function "ggplot" 

我注意到 NAMESPACE 文件不包含 ggplot 但确实存在其他导入,但是当我手动添加到 NAMESPACE 时,我收到一条错误消息:

Error in importIntoEnv(pkgenv, exports, nsenv, exports) : 
  cannot add bindings to a locked environment

我错过了什么?

【问题讨论】:

    标签: r r-package


    【解决方案1】:

    这是devtools 开发版中的一项功能。 您需要从以前安装的 github 安装它:devtools::install_github("hadley/devtools")

    Pkg 加载机制已移至pkgload。你可以在那里找到这个功能。 Pkgloaddevtools 加载,因此您无需费心。

    此答案的来源:
    rstudio 团队成员已在RStudio community forum 中询问和回答。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-23
      • 2015-02-27
      • 2021-06-19
      • 1970-01-01
      • 2014-11-29
      • 1970-01-01
      • 2019-01-31
      • 1970-01-01
      相关资源
      最近更新 更多