I have an error when installing packages offline when they have dependencies. This is very similar to this question. I have followed the instructions there to do the offline install.
So I have installed all the CRAN packages to a directory and created the PACKAGES
file also.
But there seems to be a subtle bug with the process outlined in that answer
I can install a package from the local repo on Linux with no problem using the command below i.e. not specifiying the repo:
install.packages("/software/r_packages/src/contrib/ZillowR_0.1.0.tar.gz", lib="/usr/lib64/R/library")
However, if I want to pick up the dependencies I need to point it towards the repo and its PACKAGES
file using e.g.
install.packages("/software/r_packages/src/contrib/ZillowR_0.1.0.tar.gz", lib="/usr/lib64/R/library", repos="file:///software/r_packages/")
But if I do this I get the error:
Warning message:
package ‘/software/r_packages/src/contrib/ZillowR_0.1.0.tar.gz’ is not available (for R version 3.2.3)
I've tested and confirmed it is reading the PACKAGES
file because if I put a typo into the entry for ZillowR in PACKAGES
I get an error indicating it can't parse the entry correctly.
What should work for you here is the following:
install.packages(pkgs = "ZillowR", type = "source",
lib = "/usr/lib64/R/library",
contriburl = "file:///software/r_packages/")
The arguments to install.packages()
can be pretty overwhelming and all of the defaults are configured to work with packages installed from CRAN (or another remote repository). To unpack what is going on here, consider the following code to install ZillowR from CRAN:
install.packages(pkgs = "ZillowR")
This is setting lots of defaults, so you're actually calling:
install.packages(pkgs = "ZillowR", lib = .libPaths()[1],
repos = getOption("repos"),
contriburl = contrib.url(repos, type),
type = getOption("pkgType"))
The two key defaults are calling some global options, which on my install are set to:
> getOption("repos")
CRAN CRANextra
"https://cloud.r-project.org" "http://www.stats.ox.ac.uk/pub/RWin"
> getOption("pkgType")
[1] "both"
You need to (potentially) overcome these defaults into order to do a local install and the key one to overcome is the value of contriburl
(which inherits from repos
. Knowing that, your intuition appears (rightly) to have been to follow the instructions for installing a local source package, such as:
install.packages(pkgs = "/software/r_packages/src/contrib/ZillowR_0.1.0.tar.gz", repos = NULL, type = "source")
But the behavior of install.packages()
is totally different there because the pkgs
argument is expecting the filename of a source tarball (when repos
and thus contriburl
is NULL
).
With a local CRAN-like repo, you actually want to set pkgs
to the package name and to set contriburl
to the local repo path. As a reference here's the relevant section of the docs for contriburl
:
contriburl
URL(s) of the contrib sections of the repositories. Use this argument if your repository mirror is incomplete, e.g., because you burned only the ‘contrib’ section on a CD, or only have binary packages. Overrides argument repos. Incompatible with type = "both".
The last sentence shows why you (may) need to set type = "source"
.