How to properly include dependencies in an R package?

I tried for hours to create a package in R and worry a little desperately about how slowly I progress. I managed to build the package pretty quickly without dependencies, everything works fine. Due to the recommendations in several posts, I use R Studio, devtools and Roxygen2 (while on Windows). I have problems with dependencies when I CHECK (for example, using devtools :: check ()):

checking dependencies in R-code ... NOTE. The namespace in the Import field is not imported from: 'ggplot2' All declared Imports should be used. See the DESCRIPTION file information in the Creating R Packages chapter of the Writing R-Extensions guide.

In addition, check () deletes the line import(ggplot2) in NAMESPACE. If I check (document = F), it gives a cryptic error about the digest package that is not loaded. I read “Writing R-Extensions” - 1.1.3 “Package Dependencies” and “Hadley Wiki” on how to write packages, but could not solve my problem. DESCRIPTION and NAMESPACE files from other R packages from CRAN do not look different for mine (for my eyes)?

Question: What am I doing wrong? Sorry for that basic question, but I'm at a loss and most of the walkthroughs I've seen so far stop before explaining the dependencies.

So far I have 3 files:
A DESCRIPTION:

 Package: test Type: Package Title: Foo Version: 1.0 Date: 2014-03-21 Author: Bar Maintainer: Foo < bar@mail.com > Description: Blubb Imports: ggplot2 License: GPL-3 

A NAMESPACE:

 export(is.equal.null) import(ggplot2) 

AR file:

 #' Extension of compare to include NULLs #' #' Works as an extension to usual compare #' Compares two basic objects which in addition to usual compare can be NULL #' Intuitive output: TRUE if both are equal or NULL resp., FALSE if both are unequal or only one is NULL #' #' @param obj1 Basic object like \code{numeric, char, boolean, NULL} #' @param obj2 Basic object like \code{numeric, char, boolean, NULL} #' @keywords compare #' @export #' @examples #' is.equal.null(5,5) # TRUE #' is.equal.null(5,NULL) # FALSE #' is.equal.null(NULL,NULL) # TRUE is.equal.null <- function(obj1, obj2) { # Small helper function to generalize comparison to comparison of NULL # returns TRUE if both are NULL, and FALSE if only one of the objects is NULL bool <- obj1==obj2 #qplot(obj1) if (length(bool)) return(bool) if (is.null(obj1) & is.null(obj2)) return(TRUE) return(FALSE) } 
+7
r package dependencies
source share
1 answer

You need to declare import in two places:

  • File DESCRIPTION. You should have a line similar to:

     Imports: ggplot2, pkg1, pkg2 
  • NAMESPACE file. Here you announce the packages you need.

     import(ggplot2) 

    or avoid namespace conflicts

     importFrom(ggplot2, geom_point) 

    You can get roxygen2 to support the NAMESPACE file with the @import and @importFrom .

In your example, your DESCRIPTION file looks fine, but you have not added the necessary functions to NAMESPACE.

+3
source share

All Articles