Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install a local R package with dependencies from CRAN mirror

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?

like image 714
WoDoSc Avatar asked Jul 29 '14 13:07

WoDoSc


People also ask

How do I install an R package locally?

To install a R package locally, specify the local directory where you want to install by using the “-l” option in the “R CMD INSTALL” command. For example, to install the R package in the local directory “/usr/me/localR/library”, use the “R CMD INSTALL” as follows.

How can we install packages in R with all dependencies?

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 install a package from CRAN R?

Alternatively, you can install R packages from the menu. In RStudio go to Tools → Install Packages and in the Install from option select Repository (CRAN) and then specify the packages you want. In classic R IDE go to Packages → Install package(s) , select a mirror and install the package.

What CRAN mirror should I use for R?

If you are downloading R from CRAN, the following CRAN mirrors support HTTPS and we recommend using one of them: CRAN master (Austria): https://cran.r-project.org/ RStudio (USA): https://cran.rstudio.com/ Revolution Analytics (USA): https://cran.revolutionanalytics.com/


2 Answers

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.

like image 102
Emiel Avatar answered Sep 21 '22 17:09

Emiel


If you already have installed your local package, you should be able to use a couple functions in tools to install the dependencies from CRAN:

library('tools') installFoundDepends(pkgDepends('mypackage', local = FALSE)$Found) 

Note: You can pass args (like repos) through installFoundDepends to install.packages.

You can also use the Depends element from the pkgDepends output to pass directly to install.packages:

install.packages(pkgDepends('mypackage')$Depends) 

UPDATE: Apparently it is not possible to install a local package with dependencies=FALSE. This seems odd, since you can do that for a remote package from a repository. The reason (looking at the source code) is that if(is.null(repos) & missing(contriburl)), installation is handled via system calls to R CMD INSTALL, which has no dependency-related arguments.

like image 33
Thomas Avatar answered Sep 21 '22 17:09

Thomas