Install a local R package with dependencies from CRAN mirror

WoDoSc picture WoDoSc · Jul 29, 2014 · Viewed 26.9k times · Source

I have built an R package, i.e. I have the mypackage.tar.gz file. This package depends on several other packages, all downloadable and installable from any CRAN mirror.

Now I want to install this package on a system where the dependencies are not yet installed, and I would like that the dependencies will be downloaded and installed automatically when I install my package.

I tried:

install.packages("mypackage.tar.gz",type="source",dependencies=TRUE,repos="http://a.cran.mirror")

but it searches for mypackage.tar.gz on the mirror (and obviously it does not find), while if I set repos=NULL it correctly tries to install the local package file (as documented), but obviously it does not find the dependencies packages.

So my question is: is there a way to perform a 'mixed' installation (local package with online dependencies) or the only way to do is to manually install all the dependencies?

Answer

Emiel picture Emiel · Dec 4, 2015

You could use install from the devtools package. Just run install("<directory of your package>", dependencies = TRUE). Its help states:

Uses R CMD INSTALL to install the package. Will also try to install dependencies of the package from CRAN, if they're not already installed.