Skip to content

Commit

Permalink
prompt when using an unsupported Bioc version (#1943)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Jul 11, 2024
1 parent 79e3a48 commit 5e2cccd
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 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)

* `renv::init(bioc = "<version>")` now prompts the user in interactive sessions
when requesting a version of Bioconductor which is not compatible with the
current version of R. (#1943)

* `renv::restore()` gains the `transactional` argument, which can be
used to control whether `renv` will allow successfully-installed
packages remain in the project library even if a package fails
Expand Down
57 changes: 57 additions & 0 deletions R/bioconductor.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,63 @@ renv_bioconductor_manager <- function() {
"BiocInstaller"
}

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"
)
)

}

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)
return(TRUE)

# prompt user otherwise
if (interactive()) {

fmt <- "The requested version of Bioconductor is not compatible with this version of R."
writef(fmt)

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

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

}

TRUE

}

renv_bioconductor_init <- function(library = NULL) {
renv_scope_options(renv.verbose = FALSE)

Expand Down
3 changes: 3 additions & 0 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ init <- function(project = NULL,
biocver <- renv_init_bioconductor(bioconductor, project)
if (!is.null(biocver)) {

# validate that this version of bioconductor is appropriate
renv_bioconductor_validate(version = biocver)

# make sure a Bioconductor package manager is installed
renv_bioconductor_init(library = library)

Expand Down

0 comments on commit 5e2cccd

Please sign in to comment.