Skip to content

Commit

Permalink
Only add BiocManager as dep when used (#1408)
Browse files Browse the repository at this point in the history
Includes new `renv_tests_scope_system_cache()` to make it easier to install packages from the system cache to speed up performance in tests.

Fixes #1356
  • Loading branch information
hadley committed Jun 9, 2023
1 parent 355778d commit 0041b6d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 7 deletions.
8 changes: 4 additions & 4 deletions R/status.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ renv_status_check_synchronized <- function(project,
library,
packages)
{
# projects will implicitly depend on BiocManager if any Bioconductor
# packages are in use
sources <- extract_chr(library, "Source")
# projects will implicitly depend on BiocManager & BiocVersion if any
# Bioconductor packages are in use
sources <- extract_chr(keep(library, packages), "Source")
if ("Bioconductor" %in% sources)
packages <- unique(c(packages, "BiocManager"))
packages <- union(packages, "BiocManager")

# missing dependencies -------------------------------------------------------
# Must return early because `packages` will be incomplete making later
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/_snaps/bioconductor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Bioconductor packages add BiocManager as a dependency

Code
status()
Output
The following package(s) are installed, but not recorded in the lockfile:
- BiocGenerics [<version>]
- BiocManager [<version>]
Use `renv::snapshot()` to add these packages to the lockfile.

---

Code
status()
Output
* The project is already synchronized with the lockfile.

7 changes: 7 additions & 0 deletions tests/testthat/helper-scope.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ renv_tests_scope_repos <- function(envir = parent.frame()) {
)

}

renv_tests_scope_system_cache <- function(envir = parent.frame()) {
skip_on_cran()

renv_scope_options(repos = c(CRAN = "https://cloud.r-project.org"), envir = envir)
renv_scope_envvars(RENV_PATHS_ROOT = renv_paths_root_default_impl(), envir = envir)
}
4 changes: 2 additions & 2 deletions tests/testthat/helper-snapshot.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
expect_snapshot <- function(...) {
expect_snapshot <- function(..., transform = strip_dirs) {
renv_scope_options(renv.verbose = TRUE)

testthat::expect_snapshot(..., transform = strip_dirs)
testthat::expect_snapshot(..., transform = transform)
}

strip_dirs <- function(x) {
Expand Down
33 changes: 32 additions & 1 deletion tests/testthat/test-bioconductor.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ test_that("packages can be installed, restored from Bioconductor", {
renv_tests_scope("Biobase")
renv_scope_options(repos = c(CRAN = "https://cloud.r-project.org"))

install.packages("BiocManager", quiet = TRUE)
local({
renv_tests_scope_system_cache()
install("BiocManager")
})
suppressMessages(BiocManager::install("Biobase", quiet = TRUE, update = FALSE, ask = FALSE))

expect_true(renv_package_installed("BiocManager"))
Expand Down Expand Up @@ -87,3 +90,31 @@ test_that("we can restore a lockfile using multiple Bioconductor releases", {
expect_true(renv_package_version("BiocGenerics") == "0.38.0")

})

test_that("Bioconductor packages add BiocManager as a dependency", {

renv_tests_scope()
init()
local({
renv_tests_scope_system_cache()
install("BiocManager")
install("bioc::BiocGenerics")
})

snapshot()
writeLines("library(BiocGenerics)", "dependencies.R")

expect_snapshot(
status(),
transform = function(x) gsub("\\[.*\\]", "[<version>]", x)
)
snap <- snapshot()
expect_setequal(names(snap$Packages), c("BiocManager", "BiocGenerics"))

# And it goes away when we remove the dependency
unlink("dependencies.R")
snap <- snapshot()
expect_named(snap$Packages, character())
expect_snapshot(status())

})

0 comments on commit 0041b6d

Please sign in to comment.