From ec74a93dbacc5db8e05f19c59b9447322e972943 Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Sun, 8 Oct 2023 14:27:16 +0200 Subject: [PATCH] Export `generate_installation_order` fix #154 [no ci] (#162) --- NAMESPACE | 1 + R/cache.R | 2 +- R/installation.R | 26 ++++++++++++++++++++----- man/apptainerize.Rd | 2 +- man/export_rang.Rd | 3 +++ man/generate_installation_order.Rd | 31 ++++++++++++++++++++++++++++++ tests/testthat/test_expost_rang.R | 8 ++++---- 7 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 man/generate_installation_order.Rd diff --git a/NAMESPACE b/NAMESPACE index a8046b3..a05b7ec 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/cache.R b/R/cache.R index b654c1a..1909b8e 100644 --- a/R/cache.R +++ b/R/cache.R @@ -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) diff --git a/R/installation.R b/R/installation.R index de0684a..1cef1e2 100644 --- a/R/installation.R +++ b/R/installation.R @@ -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() @@ -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. @@ -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")) { @@ -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))){ @@ -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() @@ -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. diff --git a/man/apptainerize.Rd b/man/apptainerize.Rd index f796115..491e02b 100644 --- a/man/apptainerize.Rd +++ b/man/apptainerize.Rd @@ -9,7 +9,7 @@ \alias{singularize_rang} \alias{singularise} \alias{singularise_rang} -\title{Create an Apptainer/Singularity definition file of The Resolved Result} +\title{Create an Apptainer/Singularity Definition File of The Resolved Result} \usage{ apptainerize( rang, diff --git a/man/export_rang.Rd b/man/export_rang.Rd index c78fc3f..9eb0fa6 100644 --- a/man/export_rang.Rd +++ b/man/export_rang.Rd @@ -57,3 +57,6 @@ if (interactive()) { \references{ Ripley, B. (2005) \href{https://cran.r-project.org/doc/Rnews/Rnews_2005-1.pdf}{Packages and their Management in R 2.1.0.} R News, 5(1):8--11. } +\seealso{ +\code{\link[=generate_installation_order]{generate_installation_order()}} +} diff --git a/man/generate_installation_order.Rd b/man/generate_installation_order.Rd new file mode 100644 index 0000000..2256470 --- /dev/null +++ b/man/generate_installation_order.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/installation.R +\name{generate_installation_order} +\alias{generate_installation_order} +\title{Create a Data Frame of The Resolved Result +This function exports the results from \code{\link[=resolve]{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.} +\usage{ +generate_installation_order(rang) +} +\arguments{ +\item{rang}{output from \code{\link[=resolve]{resolve()}}} +} +\value{ +A data frame ordered by installation order. +} +\description{ +Create a Data Frame of The Resolved Result +This function exports the results from \code{\link[=resolve]{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. +} +\examples{ +\donttest{ +if (interactive()) { + graph <- resolve(pkgs = c("openNLP", "LDAvis", "topicmodels", "quanteda"), + snapshot_date = "2020-01-16") + generate_installation_order(graph) +} +} +} +\references{ +Ripley, B. (2005) \href{https://cran.r-project.org/doc/Rnews/Rnews_2005-1.pdf}{Packages and their Management in R 2.1.0.} R News, 5(1):8--11. +} diff --git a/tests/testthat/test_expost_rang.R b/tests/testthat/test_expost_rang.R index 3b84396..7386fb0 100644 --- a/tests/testthat/test_expost_rang.R +++ b/tests/testthat/test_expost_rang.R @@ -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", { @@ -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) })