Skip to content

Commit

Permalink
avoid using BiocManager for validating versions
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Feb 13, 2025
1 parent 6e37dd7 commit 3ef2009
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 60 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

# renv (development version)

* Fixed an issue where `renv` could stall when loading a project and validating
that the configured version of Bioconductor is compatible with the version
of R currently in use.

* `renv::snapshot()` no longer fails to generate a new lockfile if the project
contains a lockfile which could not be read or parsed.

Expand Down
77 changes: 40 additions & 37 deletions R/bioconductor.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,58 @@ renv_bioconductor_manager <- function() {

renv_bioconductor_versions <- function() {

data.frame(

Bioc = c(
"3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.15",
"3.16", "3.17", "3.18", "3.19", "3.20", "3.20"
),

R = c(
"3.6", "3.6", "4.0", "4.0", "4.1", "4.1", "4.2",
"4.2", "4.3", "4.3", "4.4", "4.4", "4.5"
)
# map versions of Bioconductor to the versions of R they can be used with
list(
"3.9" = "3.6",
"3.10" = "3.6",
"3.11" = "4.0",
"3.12" = "4.0",
"3.13" = "4.1",
"3.14" = "4.1",
"3.15" = "4.2",
"3.16" = "4.2",
"3.17" = "4.3",
"3.18" = "4.3",
"3.19" = "4.4",
"3.20" = "4.4",
"3.21" = "4.5", # speculative
"3.22" = "4.5" # speculative
)

}

renv_bioconductor_validate <- function(version) {

# check that the requested version of Bioconductor is supported
compat <- catch({

versions <- if (getRversion() < "4.5") {
renv_bioconductor_versions()
} else {
BiocManager <- renv_namespace_load("BiocManager")
BiocManager$.version_map()
}

as.character(versions[versions$R == getRversion()[1, 1:2], "Bioc"])

})

if (inherits(compat, "error"))
return(FALSE)
else if (version %in% compat)
renv_bioconductor_validate <- function(version, prompt = interactive()) {

# check for the requested Bioconductor version in our internal version map;
# if it doesn't exist, then just assume compatibility
#
# we previously used BiocManager for this, but because it makes web requests,
# this can be prohibitively slow for certain users
#
# https://github.com/rstudio/renv/issues/2091
biocversions <- renv_bioconductor_versions()
rversion <- biocversions[[version]]
if (is.null(rversion))
return(TRUE)

# prompt user otherwise
if (interactive()) {
# check that the version of R in use matches what Bioconductor requires
ok <- renv_version_eq(rversion, getRversion(), n = 2L)
if (ok)
return(TRUE)

fmt <- "You have requested Bioconductor %s, which is not compatible with this version of R."
writef(fmt, version)
fmt <- lines(
"You are using Bioconductor %1$s, which is not compatible with R %2$s.",
"Use 'renv::init(bioconductor = TRUE)' to re-initialize this project with the appropriate Bioconductor release.",
if (renv_package_installed("BiocVersion"))
"Please uninstall the 'BiocVersion' package first, with `remove.packages(\"BiocVersion\")`."
)

fmt <- "You are using R %s, for which Bioconductor version(s) %s are available."
writef(fmt, getRversion(), paste(shQuote(compat), collapse = ", "))
caution(fmt, version, getRversion())

if (prompt) {
writef("")
response <- ask("Would you still like to use this version of Bioconductor?")
cancel_if(!response)

}

TRUE
Expand Down
24 changes: 1 addition & 23 deletions R/load.R
Original file line number Diff line number Diff line change
Expand Up @@ -644,29 +644,7 @@ renv_load_bioconductor <- function(project, bioconductor) {
}

renv_load_bioconductor_validate <- function(project, version) {

if (!identical(renv_bioconductor_manager(), "BiocManager"))
return()

BiocManager <- renv_scope_biocmanager()
if (!is.function(BiocManager$.version_validity))
return()

# check for valid version of Bioconductor
# https://github.com/rstudio/renv/issues/1148
status <- catch(BiocManager$.version_validity(version))
if (!is.character(status))
return()

fmt <- lines(
"This project is configured to use Bioconductor %1$s, which is not compatible with R %2$s.",
"Use 'renv::init(bioconductor = \"%1$s\")' to re-initialize this project with the appropriate Bioconductor release.",
if (renv_package_installed("BiocVersion"))
"Please uninstall the 'BiocVersion' package first, with `remove.packages(\"BiocVersion\")`."
)

warningf(fmt, version, getRversion())

renv_bioconductor_validate(version, prompt = FALSE)
}

renv_load_switch <- function(project) {
Expand Down

0 comments on commit 3ef2009

Please sign in to comment.