5

I'm developing a R package that depends on another R package being installed on the users system.

I've added a Depends:pkgname in the DESCRIPTION file and import(pkgname) in the NAMESPACE. What I was hoping this would do is check if pkgname is already installed and if not install.packages(pkgname,repos="CRAN or Rforge or wherever the package is") if not.

However upon attempted installation of my package i get the error:

    ERROR: dependency 'pkgname' is not available for package 'mypkg'

Does anyone know how to implement an installation of pkgname, should pkgname not already be on the system?

Many thanks

Sebastian
  • 53
  • 1
  • 3
  • If you import from a package you should put `Imports:pkgname` in DESCRIPTION not depends. It will work then if the package is installed from CRAN. – Sacha Epskamp Dec 01 '11 at 12:50

1 Answers1

4

In the help file of R CMD INSTALL there is no mention of a flag to install additional packages if needed for dependencies. If you submit your package to CRAN, your problems are solved because install.packages then solves any dependencies. install.packages does not support solving dependencies when installing from a local file.

Until you submit to either R-forge or CRAN, I think it will suffice to add a remark to the README file that a few additional packages need to be present. You could even post a snippet of R code containing the needed install.packages command.

Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149
  • Thanks! I'll be sure to add clarifying documentation regarding what people need to do for the package to work. What really helps is knowing that once the package is on CRAN/R-forge the imports will work :). – Sebastian Dec 01 '11 at 13:28
  • Yes, although note that there is a little bit of an issue (I think: perhaps someone can comment on a workaround) about installing a package from R-forge whose dependencies live on CRAN, or vice versa ... – Ben Bolker Dec 01 '11 at 14:25
  • Some of my depends might even live on bioconductor ^^ – Sebastian Dec 01 '11 at 14:54
  • Lol, then it might be better to write a good install script that install all the appropriate packages in the correct order. – Paul Hiemstra Dec 01 '11 at 15:18