I was trying now for several hours to build a package in R and getting a bit desperate about how slowly I progress. I managed quite fast to build a package with no dependencies, everything works fine. Due to recommendations in several posts, I'm using R Studio, devtools and Roxygen2 (being on Windows). With dependencies, I get problems when I CHECK (e.g. with devtools::check() ):
checking dependencies in R code ... NOTE Namespace in Imports field not imported from: 'ggplot2' All declared Imports should be used. See the information on DESCRIPTION files in the chapter 'Creating R packages' of the 'Writing R Extensions' manual.
Furthermore, check() deletes the import(ggplot2)
line in the NAMESPACE. If I do check(document=F), it gives an cryptic error about a digest
package which is not loaded. I read 'Writing R Extensions' - 1.1.3 Package Dependencies and Hadley's Wiki concerning how to write packages, but couldn't solve my problem. DESCRIPTION and NAMESPACE files of other R packages from CRAN don't look different to mine (for my eyes)?
Question: What am I doing wrong? Sorry for such a basic question, but I am at a loss and most step-by-step tutorials I've seen so far stop before explaining 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)
A R-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)
}
You need to declare imports in two places:
The DESCRIPTION file. You should have a line similar to:
Imports: ggplot2, pkg1, pkg2
The NAMESPACE file. Here you declare the packages you need
import(ggplot2)
or to avoid namespace clashes
importFrom(ggplot2, geom_point)
You can get roxygen2 to maintain the NAMESPACE file using the @import
and @importFrom
tags.
In your example your DESCRIPTION file looks OK, but you haven't added the necessary functions to the NAMESPACE.