Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package dependencies for R base packages [duplicate]

Tags:

r

cran

r-package

When writing a package in R, is it necessary to add base packages (utils, grDevices, stats, etc.) as dependencies in the DESCRIPTION of your package?

Some packages do this, but most seem to not.

I have not found any information in the Writing R Extensions manual regarding this.

like image 758
Johan Larsson Avatar asked Nov 09 '22 09:11

Johan Larsson


1 Answers

You should not set too much dependencies but prefer to use those packages as import :

for instance in the DESCRIPTION you will write

     Imports:    
     graphics,
     utils,
     stats,
     grDevices

In your NAMESPACE you can then use either importFrom, in the case you only have a few functions to use. Then you don't have to point to the function using pkg::fun(), or import pkg which will import the whole package, and again you will not need to use the pkg::fun().

Below an example of what you can write in your NAMESPACE

    import(graphics)
    importFrom(stats,coef)
    importFrom(stats,ftable)
    importFrom(stats,na.fail)
    importFrom(utils,data)
    importFrom(utils,globalVariables)
    importFrom(utils,read.csv)
    importFrom(utils,select.list)
    importFrom(utils,stack)
    importFrom(utils,write.table)

If you try to use those functions without importing them or use depends, the R-CMD check will fail.

like image 131
Cedric Avatar answered Nov 15 '22 07:11

Cedric