Skip to content

Commit

Permalink
package_find_repos works properly with multiple repos provided
Browse files Browse the repository at this point in the history
Fixes r-lib#943
  • Loading branch information
jimhester committed Jan 15, 2016
1 parent 3251999 commit 3be5877
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
17 changes: 12 additions & 5 deletions R/install-version.r
Expand Up @@ -41,7 +41,7 @@ install_version <- function(package, version = NULL, repos = getOption("repos"),
}
}

url <- paste(repos, "/src/contrib/Archive/", package.path, sep = "")
url <- paste(info$repo[1L], "/src/contrib/Archive/", package.path, sep = "")
install_url(url, ...)
}

Expand All @@ -50,13 +50,20 @@ package_find_repo <- function(package, repos) {
if (length(repos) > 1)
message("Trying ", repo)

con <- gzcon(url(sprintf("%s/src/contrib/Meta/archive.rds", repo), "rb"))
on.exit(close(con))
archive <- readRDS(con)
archive <-
tryCatch({
con <- gzcon(url(sprintf("%s/src/contrib/Meta/archive.rds", repo), "rb"))
on.exit(close(con))
readRDS(con)
},
warning = function(e) list(),
error = function(e) list())

info <- archive[[package]]
if (!is.null(info))
if (!is.null(info)) {
info$repo <- repo
return(info)
}
}

stop(sprintf("couldn't find package '%s'", package))
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-install-version.R
@@ -0,0 +1,13 @@
context("Install specific version")

test_that("package_find_repo() works correctly with multiple repos", {

repos <- c(CRANextras = "https://www.stats.ox.ac.uk/pub/RWin", CRAN = "https://cran.rstudio.com")
# ROI.plugin.glpk is the smallest package in the CRAN archive
package <- "ROI.plugin.glpk"
res <- package_find_repo(package, repos = repos)

expect_equal(NROW(res), 1L)
expect_equal(res$repo, "https://cran.rstudio.com")
expect_match(rownames(res), package)
})

0 comments on commit 3be5877

Please sign in to comment.