Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install dependencies when using "R CMD INSTALL" to install R packages?

I'm developing my first R package (using R 2.13, Ubuntu 10.10). Let's call it foo and let's say that the code in the R/ directory begins with the line library(bar), where bar is an existing package, in CRAN, on which foo depends. My DESCRIPTION file contains the line:

Depends: bar 

When package foo is ready for testing, I install it locally using:

R CMD INSTALL foo_1.0.tar.gz 

However, if bar is not installed, I see:

ERROR: dependency ‘bar’ is not available for package ‘foo’ 

Obviously, if my foo were installed from CRAN using install.packages(), bar would be installed at the same time. So my question is: how can I ensure that CRAN package bar is installed, if required, when I install my package foo using R CMD INSTALL? Is this a job for a configuration script?

like image 241
neilfws Avatar asked Aug 02 '11 06:08

neilfws


People also ask

How do I install dependencies in R?

Remember in R, Boolean (TRUE and FALSE) must be all capital letters or R will not recognize them as Boolean. At the top, got to Tools and select Install Packages from the drop down. Finally, make sure install dependencies and checked and click install.

How do I manually install an R package?

Go into R, click on Packages (at the top of the R console), then click on "Install package(s) from local zip files", then find the zip file with arm from wherever you just saved it. Do the same thing to install each of the other packages you want to install.

Which command in R is used to install R packages?

To install any package from CRAN, you use install. packages() . You only need to install packages the first time you use R (or after updating to a new version). **R Tip:** You can just type this into the command line of R to install each package.


2 Answers

Actually, re-reading the R extensions guide, it doesn't say that R CMD INSTALL will get dependencies from CRAN. The install.packages() method from within R will do that, but at first glance I don't think R CMD INSTALL does.

You can use install.packages to install from a .tar.gz, but you have to set repos=NULL, and then this applies:

 dependencies: logical indicating to also install uninstalled packages           on which these packages depend/suggest/import (and so on           recursively).  Not used if repos = NULL. 

I suspect the thing to do is to get the dependencies out of the DESCRIPTION file and then run R and do an install.packages() on those when you are testing your build in a clean environment.

like image 186
Spacedman Avatar answered Sep 25 '22 19:09

Spacedman


Fortunately Devtools provides an easy solution: install_deps()

install_deps(pkg = ".", dependencies = logical, threads = getOption("Ncpus",1))

Arguments:
pkg: package description, can be path or package name. See ‘as.package’ for more information

dependencies: ‘logical’ indicating to also install uninstalled packages which this ‘pkg’ depends on/links to/suggests. See argument ‘dependencies’ of ‘install.packages’.

threads: number of concurrent threads to use for installing dependencies. It defaults to the option ‘"Ncpus"’ or ‘1’ if unset.

Examples:

 install_deps(".")   install_deps("/path/to/package",dependencies="logical") 
like image 34
igauravsehrawat Avatar answered Sep 23 '22 19:09

igauravsehrawat