Skip to content

Commit

Permalink
ensure required fields are present in available_packages call
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Mar 7, 2023
1 parent 9fd57df commit 7aa92a0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: renv
Type: Package
Title: Project Environments
Version: 0.17.0-22
Version: 0.17.0-23
Authors@R: c(
person("Kevin", "Ushey", role = c("aut", "cre"), email = "[email protected]"),
person("Posit Software, PBC", role = c("cph", "fnd"))
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# renv 0.18.0 (UNRELEASED)

* Fixed an issue where `renv` would fail to query [r-universe](https://r-universe.dev/)
repositories. (#1156)

* `renv` no longer tries to set the `SDKROOT` environment variable on
macOS for R (>= 4.0.0).

Expand Down
22 changes: 18 additions & 4 deletions R/available-packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ renv_available_packages_impl <- function(type, repos, quiet = FALSE) {
# request repositories
urls <- contrib.url(repos, type)
errors <- new.env(parent = emptyenv())
dbs <- lapply(urls, renv_available_packages_query, errors = errors)
dbs <- map(urls, renv_available_packages_query, type = type, errors = errors)
names(dbs) <- names(repos)

# notify finished
Expand Down Expand Up @@ -95,7 +95,7 @@ renv_available_packages_query_packages <- function(url) {
suppressWarnings(read.dcf(destfile))
}

renv_available_packages_query <- function(url, errors) {
renv_available_packages_query <- function(url, type, errors) {

# define query methods for the different PACKAGES
methods <- list(
Expand Down Expand Up @@ -125,7 +125,7 @@ renv_available_packages_query <- function(url, errors) {
next
}

return(renv_available_packages_success(db, url))
return(renv_available_packages_success(db, url, type))

}

Expand All @@ -134,13 +134,27 @@ renv_available_packages_query <- function(url, errors) {

}

renv_available_packages_success <- function(db, url) {
renv_available_packages_success <- function(db, url, type) {

# convert to data.frame
db <- as.data.frame(db, row.names = FALSE, stringsAsFactors = FALSE)
if (nrow(db) == 0L)
return(db)

# add in necessary missing columns
required <- c(
"Package", "Version", "Priority",
"Depends", "Imports", "LinkingTo", "Suggests", "Enhances",
"License", "License_is_FOSS", "License_restricts_use",
"OS_type", "Archs", "MD5sum",
if (type %in% "source") "NeedsCompilation",
"File"
)

missing <- setdiff(required, names(db))
db[missing] <- NA_character_
db <- db[required]

# filter as appropriate
db <- renv_available_packages_filter(db)

Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/test-available-packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,24 @@ test_that("we're compatible with R", {
expect_equal(lhs[fields], rhs[fields])

})

test_that("we can query the R universe", {
skip_on_cran()
skip_sometimes()

lhs <- as.data.frame(
available.packages(
type = "source",
repos = "https://rstudio.r-universe.dev"
)
)

rhs <- available_packages(
type = "source",
repos = "https://rstudio.r-universe.dev/"
)[[1L]]

rownames(lhs) <- rownames(rhs) <- NULL
expect_identical(lhs, rhs)

})

0 comments on commit 7aa92a0

Please sign in to comment.