83

I am trying to build an R package so reading the manual on CRAN. I could figure out that using imports to load functions in your namespace would be the best bet to use in the Description file. After adding to the description file, I also added it to the namespace file. I added importFrom to the namespace file with the functions required.

Now when I run R CMD check on my package, I get an ERROR as

Namespace dependencies not required : 'ggplot2'

Further information : Even if I add the package to the Depends in the description file, they are not getting loaded.

Please help with this.

Please find my description file below

Package: bigpackage Type: Package Title: Some title Version: 1.0 Date: 2012-10-25 Author: Mayank Bansal Maintainer: somename Imports : R(>= 2.15.1), SweaveListingUtils( >=0.5.5),xtable(>=1.7-0), brew(>=1.0-6), knitr(>=0.8), RHive(>= 0.0-6), ggplot2(>=0.9.2) , brew, knitr SystemRequirements : LaTeX(texi2dvi) must be present in the system to create PDF reports Description: Some Description License: file LICENSE LazyLoad: yes ByteCompile: true OS_type : unix 
1
  • 1
    Are you importing anything from ggplot2 directly in your NAMESPACE file? Commented Oct 26, 2012 at 17:25

2 Answers 2

106

If you use import or importFrom in your NAMESPACE file, you should have an entry for that package in the Imports section of your DESCRIPTION file (unless there is a reason that you need to use Depends in which case the package should have an entry in Depends, and not Imports)

Here is a relevant section of Writing R Extensions

The ‘Imports’ field lists packages whose namespaces are imported from (as specified in the NAMESPACE file) but which do not need to be attached. Namespaces accessed by the ‘::’ and ‘:::’ operators must be listed here, or in ‘Suggests’ or ‘Enhances’ (see below). Ideally this field will include all the standard packages that are used, and it is important to include S4-using packages (as their class definitions can change and the DESCRIPTION file is used to decide which packages to re-install when this happens). Packages declared in the ‘Depends’ field should not also be in the ‘Imports’ field.


I made a package with a single function f. I made a NAMESPACE file with the same importFrom line that you say you have in yours.

NAMESPACE file

export("f") importFrom("ggplot2","ggplot","geom_histogram") 

At this point, if I run R CMD check, as expected, I get an error:

Namespace dependency not required: ‘ggplot2’

But, if I add Imports: ggplot2 to the DESCRIPTION such that my DESCRIPTION file is as follows, it passes R CMD check with no problems.

DESCRIPTION file

Package: anRpackage Type: Package Title: What the package does (short line) Version: 1.0 Date: 2012-11-07 Author: Me Maintainer: Who to complain to <[email protected]> Description: More about what it does (maybe more than one line) License: GPL Imports: ggplot2 
Sign up to request clarification or add additional context in comments.

17 Comments

Won't it fail R CMD check if you don't include the Imports section in the DESCRIPTION though?
@Dason, No. See the DESCRIPTION and NAMESPACE of the xts package for example... Depends: ggplot2 may need to be in the DESCRIPTION file for the OP though
You should have it in the imports field, and not in the depends field.
@GSee - yeah but that has zoo under depends and doesn't have any imports of zoo in the namespace. I was saying that if you have an imports in your namespace but don't list the import in your DESCRIPTION then it will fail R CMD check - correct? I think the OP is just confused about what an import does exactly and they're expected that it behaves similar to Depends. If they want to use Depends then they don't need to add the package to their namespace and if they want to use imports they need something in an Imports field and in the namespace.
Finally! you've shown your DESCRIPTION file. Now the problem is clear. You have a space between "Imports" and ":", it should be Imports: , not Imports :
|
10

A simple reason this can happen is if you accidentally used commas when declaring @import in any/all of your functions

E.g. incorrect:

#' #' @import rvest, dplyr, stringr, jsonlite #' #' @export #' 

correct:

#' #' @import rvest dplyr stringr jsonlite #' #' @export #' 

This is a common error since packages are comma-separated in the DESCRIPTION file

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.