简体   繁体   中英

Import doesn't import in r package development

I am trying to create a package. I use the ggplot2 library for one of the functions.

I have written the import statement for the function:

#' @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

and written Imports:ggplot2 in the DESCRIPTION as below

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

whenever I run load_all() or document() from the devtools I get the error:

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

I have noticed that the NAMESPACE file does not contain ggplot but does have the other imports present but when I add to the NAMESPACE manually I get an error saying:

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

What have I missed?

This is a feature in the devel version of devtools . You need to install it from github from a previous install : devtools::install_github("hadley/devtools")

Pkg loading mechanisms have been move to pkgload . You can find this feature there. Pkgload is loaded by devtools so you don't need to bother.

Source for this answer:
It has been asked and answered in RStudio community forum by a rstudio team member.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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