How to tell CRAN to install package dependencies automatically?
Asked Answered
K

2

83

I develop a package in R and when I check and build it in my local computer it works properly. But when I tried it in CRAN, I get a package dependencies error. My package depends on two functions of other packages.

If I list the other packages under the description using Depends or imports, will it be automatically installed with the new package? Or do I need to explicitly invoke the function install.packages("packagename") under the function that I've used the other packages. if this all is wrong, what is the best way to solve package dependencies in R inorder to pass the R CMD check and build test and submit to CRAN?

Thank you.

Kokura answered 5/1, 2013 at 11:5 Comment(2)
yes, list the other packages after Depends: in your DESCRIPTION fileMarilou
An easy test to use is to remove package X from your system and see if your package installs X from the Depends.Fantast
G
91

On your own system, try

install.packages("foo", dependencies=...)

with the dependencies= argument is documented as

dependencies: logical indicating to also install uninstalled packages
      which these packages depend on/link to/import/suggest (and so
      on recursively).  Not used if ‘repos = NULL’.  Can also be a
      character vector, a subset of ‘c("Depends", "Imports",
      "LinkingTo", "Suggests", "Enhances")’.

      Only supported if ‘lib’ is of length one (or missing), so it
      is unambiguous where to install the dependent packages.  If
      this is not the case it is ignored, with a warning.

      The default, ‘NA’, means ‘c("Depends", "Imports",
      "LinkingTo")’.

      ‘TRUE’ means (as from R 2.15.0) to use ‘c("Depends",
      "Imports", "LinkingTo", "Suggests")’ for ‘pkgs’ and
      ‘c("Depends", "Imports", "LinkingTo")’ for added
      dependencies: this installs all the packages needed to run
      ‘pkgs’, their examples, tests and vignettes (if the package
      author specified them correctly).

so you probably want a value TRUE.

In your package, list what is needed in Depends:, see the Writing R Extensions manual which is pretty clear on this.

Gardas answered 5/1, 2013 at 14:52 Comment(3)
@ dirk, thanks. But now I've got where the problem is occurred. When I run R CMD check on R-forge it has a package dependency error with linux-x86-64 platform. but there was no error for windows and mac OS. the error message looks like this: using platform: x86_64-unknown-linux-gnu (64-bit) * checking package dependencies ... ERROR Packages required but not available: ‘isa2’ ‘fabia’Kokura
... and what if I removed a package? I would like to remove all its dependencies as long as they are not required by some other already installed packages?Sikhism
@andi: it's often not that simple. Installation of dependencies can fail, if they require compilation on your platform (or if the version that CRAN insists on downloading is source, even though binary distributions may be available elsewhere). xgboost used to be notorious for this, for example.Ornithosis
S
5

Another possibility is to select the Install Dependencies checkbox In the R package installer, on the bottom right:

enter image description here

Snakebird answered 26/11, 2016 at 9:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.