Install a Local R Package with Dependencies from Cran Mirror

Package dependencies when installing from source in R

You could make your own repository and set repos to be a vector of the places to look for packages, where it would start with your own repository and then include a link to a CRAN mirror. This is what I do and it works quite nicely, as then I can easily share my packages with others and update them from whatever computer I happen to be on.

Install dependencies of custom package

Figured it out.

The problem was a misunderstanding on my part regarding roxygen, which I've been using for my documentation. I assumed it handled the Imports: section of the DESCRIPTION file, which it doesn't ((1), (2)). So while the NAMESPACE file has all the necessary importFrom(pool, ...) calls, pool wasn't actually on my DESCRIPTION.

After fixing that oversight, using remote::install_local("path/to/pkg") (or devtools::install()) ((3)) worked: it installed my package and pulled its dependencies from CRAN.

Offline install of R package and dependencies

The correct answer was given by Joshua Ulrich in the comment on the question:

The key is prefixing the argument to either repos or contriburl with file://. So in Unixy systems one could do:

install.packages("ggplot2", contriburl="file:///path/to/packages/")

This assumes that all required source packages, as well as a PACKAGES index file is available in /path/to/packages. If no PACKAGES file is present, this should be generated first using:

library(tools)
write_PACKAGES("/path/to/packages/")

which will generate an index of all source packages found in this directory. Note that in the example, there are 3 slashes behind the file: prefix. The third slash indicates a path relative to the root of the file system.

The difference between the repos and contriburl argument is that repos will append another /src/contrib to the path specified, as this is usually where source packages are located on an official CRAN repository mirror.

R, install package from source vs. use install.package() and CRAN mirror

You hit an important overall question -- "should I install from a binary repository (where available) or should I install from source" -- but I fear you are a little confused about other aspects:

  • You rightly point to the Debian and Ubuntu READMEs. Ubuntu is particularly useful as Michael's (off-CRAN) PPA repos provide about 3200 package that are directly installable as binaries. Nothing is faster.

  • But that is for Ubuntu and you run CentOS. No soup for you.

  • So source installation it is.

  • And source installation is always from a .tar.gz and the various methods you list (command-line, install.packages(), ...) and alternative (Package tab in RStudio, say) are all equivalent as the all call the same underlying function.

It is really just different veneer for convenience.

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

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.



Related Topics



Leave a reply



Submit