Namespace dependencies not required

后端 未结 2 1030
旧时难觅i
旧时难觅i 2020-12-05 03:45

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 th

相关标签:
2条回答
  • 2020-12-05 04:19

    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 <yourfault@somewhere.net>
    Description: More about what it does (maybe more than one line)
    License: GPL
    Imports: ggplot2
    
    0 讨论(0)
  • 2020-12-05 04:34

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

    E.g. this

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

    would change to this

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

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

    0 讨论(0)
提交回复
热议问题