Skip to content

Commit

Permalink
search repositories for unknown and local packages
Browse files Browse the repository at this point in the history
fixes #1004
  • Loading branch information
aronatkins committed Sep 27, 2023
1 parent 03bce80 commit ab78138
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 13 deletions.
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* Do not use `getOption("available_packages_filters")` option when calling
`available.packages()`. (#1002)

* Packages installed from source within an renv project are not associated
with repositories. (#1004)
* The configured repositories are searched for packages installed into an renv
project from local or unknown sources. (#1004)

# rsconnect 1.1.0

Expand Down
6 changes: 5 additions & 1 deletion R/bundlePackagePackrat.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ standardizePackratPackage <- function(record, availablePackages, repos = charact

findRepoName <- function(repository, repos) {
idx <- match(repository, repos)
names(repos)[idx]
if (!is.na(idx)) {
names(repos)[idx]
} else {
NA_character_
}
}

findRepoUrl <- function(pkg, availablePackages) {
Expand Down
9 changes: 7 additions & 2 deletions R/bundlePackageRenv.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,13 @@ standardizeRenvPackage <- function(pkg,
} else if (pkg$Source %in% c("Bitbucket", "GitHub", "GitLab")) {
pkg$Source <- tolower(pkg$Source)
} else if (pkg$Source %in% c("Local", "unknown")) {
pkg$Source <- NA_character_
pkg$Repository <- NA_character_
# When installed from source or using some unknown technique, try to find
# the package from the known set of repositories.
#
# The incoming (optional) $Repository comes from DESCRIPTION and is set by
# the repository and can be anything.
pkg$Repository <- findRepoUrl(pkg$Package, availablePackages)
pkg$Source <- findRepoName(pkg$Repository, repos)
}

# Remove Remote fields that pak adds for "standard" installs from CRAN
Expand Down
70 changes: 62 additions & 8 deletions tests/testthat/test-bundlePackageRenv.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,72 @@ test_that("packages installed from other repos get correctly named", {
)
})

test_that("source packages get NA source + repository", {
source <- list(Package = "pkg", Source = "unknown", Repository = "useless")
test_that("source packages are looked up", {
repos <- c(CRAN = "https://cran.r-project.org")
ap <- availablePackages(repos)

# unknown package name
source <- list(
Package = "package.does.not.exist",
Source = "unknown",
Repository = "useless"
)
expect_equal(
standardizeRenvPackage(source, ap, repos = repos),
list(
Package = "package.does.not.exist",
Source = NA_character_,
Repository = NA_character_
)
)

# known package name
source <- list(
Package = "shiny",
Source = "unknown",
Repository = "useless"
)
expect_equal(
standardizeRenvPackage(source),
list(Package = "pkg", Source = NA_character_, Repository = NA_character_)
standardizeRenvPackage(source, ap, repos = repos),
list(
Package = "shiny",
Source = "CRAN",
Repository = "https://cran.r-project.org"
)
)
})

test_that("Local packages get NA source + repository", {
source <- list(Package = "pkg", Source = "Local", Repository = "useless")
test_that("Local packages are looked up", {
repos <- c(CRAN = "https://cran.r-project.org")
ap <- availablePackages(repos)

# unknown package name
source <- list(
Package = "package.does.not.exist",
Source = "Local",
Repository = "useless"
)
expect_equal(
standardizeRenvPackage(source, ap, repos = repos),
list(
Package = "package.does.not.exist",
Source = NA_character_,
Repository = NA_character_
)
)

# known package name
source <- list(
Package = "shiny",
Source = "Local",
Repository = "useless"
)
expect_equal(
standardizeRenvPackage(source),
list(Package = "pkg", Source = NA_character_, Repository = NA_character_)
standardizeRenvPackage(source, ap, repos = repos),
list(
Package = "shiny",
Source = "CRAN",
Repository = "https://cran.r-project.org"
)
)
})

0 comments on commit ab78138

Please sign in to comment.