简体   繁体   中英

what is the behavior of install.packages in case multiple repos are specified?

It is not clear from the documentation what is the behavior if multiple repos are specified at install.packages. My intuition told me that it would try the first repo, and if the package is not found, it would try the second, and so on. Unfortunately it does not appear to be the case. What I see is that only the first is tried, and an error is returned (because the repo does not contain the package). There's also lack of clarity of how the "CRAN" entry is handled compared to a different entry.

What I want to have is a local CRAN with my own packages (specified first), and the global CRAN with the larger package sets (specified second), and be able to install from the local unless the package is not found (and in that case, it will fall back to the global)

Here is the error I get

> setRepositories(graphics = FALSE, ind=NULL, addURLs=c(ciccio="file:qs-cran", CRAN="https://mran.microsoft.com/snapshot/2018-08-01"))
> install.packages("zizzio")
Error in read.dcf(file = tmpf) : cannot open the connection
In addition: Warning messages:
1: package ‘zizzio’ is not available (for R version 3.5.3) 
2: In read.dcf(file = tmpf) :
  cannot open compressed file 'qs-cran/bin/macosx/el-capitan/contrib/3.5/PACKAGES', probable reason 'No such file or directory'
> install.packages("zizzio", type="source")
Warning message:
package ‘zizzio’ is not available (for R version 3.5.3) 

I think your problem is that your local repository doesn't have a PACKAGES file. Every directory in a repo that has packages must have this file, because it's how R knows what's available. So R tries that repo first, hits an error when the file it needs doesn't exist, and stops before looking at the next repo.

The official manual "R Installation and Administration" describes what's necessary for a repository .

You can create the PACKAGES file with:

tools::write_PACKAGES(
  "qs-cran/bin/macosx/el-capitan/contrib/3.5",
  type = "mac.binary"
)

Afterwards, your repository should look like this:

qs-cran/
└ bin/macosx/el-capitan/contrib/3.5/
    ├ PACKAGES
    └ zizzio_1.0.0.zip

From then on, anytime you add, change, or remove a package, use:

tools::update_PACKAGES(
  "qs-cran/bin/macosx/el-capitan/contrib/3.5",
  type = "mac.binary"
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM