Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export generate_installation_order fix #154 #162

Merged
merged 1 commit into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export(dockerize)
export(dockerize_rang)
export(export_rang)
export(export_renv)
export(generate_installation_order)
export(query_sysreqs)
export(resolve)
export(singularise)
Expand Down
2 changes: 1 addition & 1 deletion R/cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ NULL
}

.cache_pkgs <- function(rang, base_dir, cran_mirror, bioc_mirror, verbose) {
installation_order <- .generate_installation_order(rang)
installation_order <- generate_installation_order(rang)
cache_dir <- file.path(base_dir, "cache", "rpkgs")
if (!dir.exists(cache_dir)) {
dir.create(cache_dir, recursive = TRUE)
Expand Down
26 changes: 21 additions & 5 deletions R/installation.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@
}
}

.generate_installation_order <- function(rang) {
#' Create a Data Frame of The Resolved Result
#' This function exports the results from [resolve()] to a data frame, which each row represents one installation step. The order of rows is the installation order. By installing packages in the specified order, one can install all the resolved packages without conflicts.
#' @inheritParams export_rang
#' @return A data frame ordered by installation order.
#' @references
#' Ripley, B. (2005) [Packages and their Management in R 2.1.0.](https://cran.r-project.org/doc/Rnews/Rnews_2005-1.pdf) R News, 5(1):8--11.
#' @examples
#' \donttest{
#' if (interactive()) {
#' graph <- resolve(pkgs = c("openNLP", "LDAvis", "topicmodels", "quanteda"),
#' snapshot_date = "2020-01-16")
#' generate_installation_order(graph)
#' }
#' }
#' @export
generate_installation_order <- function(rang) {
dep <- fastmap::fastmap()
version <- fastmap::fastmap()
uid <- fastmap::fastmap()
Expand Down Expand Up @@ -133,6 +148,7 @@
#' @param check_cran_mirror logical, whether to check the CRAN mirror
#' @param bioc_mirror character, which Bioconductor mirror to use
#' @return `path`, invisibly
#' @seealso [generate_installation_order()]
#' @details The idea behind this is to determine the installation order of R packages locally. Then, the installation script can be deployed to another
#' fresh R session to install R packages. [dockerize()] and [apptainerize()] are more reasonable ways because a fresh R session with all system requirements
#' is provided. The current approach does not work in R < 2.1.0.
Expand Down Expand Up @@ -166,7 +182,7 @@ export_rang <- function(rang, path, rang_as_comment = TRUE, verbose = TRUE, lib
if (.is_r_version_older_than(rang, "3.3")) { #20
cran_mirror <- .normalize_url(cran_mirror, https = FALSE)
}
installation_order <- .generate_installation_order(rang)
installation_order <- generate_installation_order(rang)
file.create(path)
con <- file(path, open="w")
if (.is_r_version_older_than(rang, "2.1")) {
Expand Down Expand Up @@ -219,7 +235,7 @@ export_renv <- function(rang, path = ".") {
warning("Nothing to export.")
return(invisible(NULL))
}
pkg_df <- .generate_installation_order(rang)
pkg_df <- generate_installation_order(rang)
pkg_list <- vector(mode = "list",length = nrow(pkg_df))
names(pkg_list) <- pkg_df$x
for(i in seq_len(nrow(pkg_df))){
Expand All @@ -234,7 +250,7 @@ export_renv <- function(rang, path = ".") {
pkg_list[[i]][["RemoteType"]] <- "GitHub"
pkg_list[[i]][["RemoteHost"]] <- "api.github.com"
pkg_list[[i]][["RemoteRepo"]] <- pkg_df$x[i]
pkg_list[[i]][["RemoteUsername"]]<- strsplit(pkg_df$handle[i],"/")[[1]][1]
pkg_list[[i]][["RemoteUsername"]] <- strsplit(pkg_df$handle[i],"/")[[1]][1]
pkg_list[[i]][["RemoteRef"]] = "HEAD"
pkg_list[[i]][["RemoteSha"]] = pkg_df$uid[i]
# pkg_list[[i]][["Requirements"]] <- c()
Expand Down Expand Up @@ -467,7 +483,7 @@ dockerize <- function(rang, output_dir, materials_dir = NULL, post_installation_
output_file = "Dockerfile")
}

#' Create an Apptainer/Singularity definition file of The Resolved Result
#' Create an Apptainer/Singularity Definition File of The Resolved Result
#'
#' This function exports the result from [resolve()] to an Apptainer/Singularity definition file. For R version >= 3.1.0, the file is based on the versioned Rocker Docker image.
#' For R version < 3.1.0, the Apptainer/Singularity definition is based on Debian and it compiles R from source.
Expand Down
2 changes: 1 addition & 1 deletion man/apptainerize.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/export_rang.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions man/generate_installation_order.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/testthat/test_expost_rang.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ test_that("empty rang export, #75", {
test_that("prevent infinite loop, #81", {
graph <- readRDS("../testdata/rang_ok.RDS")
graph$ranglets[[1]]$deps[[2]] <- NULL
expect_error(.generate_installation_order(graph), "cran::LDAvis")
expect_error(generate_installation_order(graph), "cran::LDAvis")
graph <- readRDS("../testdata/rang_ok.RDS")
graph$ranglets[[1]]$original$y <- "S4Vectors"
graph$ranglets[[1]]$original$y_pkgref <- "bioc::S4Vectors"
expect_error(.generate_installation_order(graph), "cran::LDAvis")
expect_error(generate_installation_order(graph), "cran::LDAvis")
})

test_that("renv export cran", {
Expand Down Expand Up @@ -183,10 +183,10 @@ test_that("renv export unknown source", {

test_that("Super ancient special packages", {
graph <- readRDS("../testdata/superancientsna.RDS")
expect_error(.generate_installation_order(graph), NA)
expect_error(generate_installation_order(graph), NA)
})

test_that("base as a dependency, issue 144", {
graph <- readRDS("../testdata/dt.RDS")
expect_error(.generate_installation_order(graph), NA)
expect_error(generate_installation_order(graph), NA)
})