我正在尝试创建一个包。我将ggplot2
库用于其中一个函数。
我已经为函数编写了import语句:
#' @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
我错过了什么?
答案 0 :(得分:1)
这是devtools
的开发版本中的一项功能。
您需要从之前的安装中的github安装它:devtools::install_github("hadley/devtools")
Pkg加载机制已移至pkgload
。你可以在那里找到这个功能。 Pkgload
加载了devtools
,因此您无需费心。
这个答案的来源:
它已在RStudio community forum由一名rstudio团队成员提出并回答。