From 8709e58925800b3bf6823ed94399be540fcde081 Mon Sep 17 00:00:00 2001 From: schochastics Date: Fri, 10 Feb 2023 18:05:05 +0100 Subject: [PATCH 1/2] possible to add material to output_dir --- R/installation.R | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/R/installation.R b/R/installation.R index b670e7e..a47b3cf 100644 --- a/R/installation.R +++ b/R/installation.R @@ -161,7 +161,14 @@ basic_docker[gran_line:length(basic_docker)]) } -.generate_pre310_docker <- function(r_version, debian_version = "lenny", lib, sysreps_cmd, cache) { +.insert_material_dir <- function(basic_docker){ + gran_line <- which(basic_docker == "COPY gran.R ./gran.R") + c(basic_docker[1:gran_line], + "COPY material/ ./material/", + basic_docker[(gran_line+1):length(basic_docker)]) +} + +.generate_pre310_docker <- function(material_dir,r_version, debian_version = "lenny", lib, sysreps_cmd, cache) { basic_docker <- c( paste0("FROM debian/eol:", debian_version), "ENV TZ UTC", @@ -250,6 +257,7 @@ export_granlist <- function(granlist, path, granlist_as_comment = TRUE, verbose #' This function exports the result from [resolve()] to a Docker file. For R version >= 3.1.0, the Dockerfile is based on the versioned Rocker image. #' For R version < 3.1.0, the Dockerfile is based on Debian and it compiles R from source. #' @param output_dir where to put the Docker file +#' @param material_dir additional resources (e.g. analysis scripts) to be copied into `output_dir` #' @param image character, which versioned Rocker image to use. Can only be "r-ver", "rstudio", "tidyverse", "verse", "geospatial". #' This applies only to R version <= 3.1 #' @param cache logical, whether to cache the content from CRAN now. Please note that the system requirements are not cached @@ -270,7 +278,7 @@ export_granlist <- function(granlist, path, granlist_as_comment = TRUE, verbose #' } #' } #' @export -dockerize <- function(granlist, output_dir, image = c("r-ver", "rstudio", "tidyverse", "verse", "geospatial"), +dockerize <- function(granlist, output_dir, material_dir = NULL, image = c("r-ver", "rstudio", "tidyverse", "verse", "geospatial"), granlist_as_comment = TRUE, cache = FALSE, verbose = TRUE, lib = NA, cran_mirror = "https://cran.r-project.org/", check_cran_mirror = TRUE) { if (missing(output_dir)) { @@ -297,7 +305,7 @@ dockerize <- function(granlist, output_dir, image = c("r-ver", "rstudio", "tidyv if (utils::compareVersion(granlist$r_version, "3.1") == -1) { file.copy(system.file("compile_r.sh", package = "gran"), file.path(output_dir, "compile_r.sh"), overwrite = TRUE) - basic_docker <- .generate_pre310_docker(r_version = granlist$r_version, + basic_docker <- .generate_pre310_docker(material_dir, r_version = granlist$r_version, sysreps_cmd = sysreps_cmd, lib = lib, cache = cache) } else { @@ -315,6 +323,20 @@ dockerize <- function(granlist, output_dir, image = c("r-ver", "rstudio", "tidyv basic_docker <- .insert_cache_dir(basic_docker) } } + if(!is.null(material_dir)){ + if(!dir.exists(material_dir)){ + stop(paste0("The folder ",material_dir," does not exist"),call. = FALSE) + } else{ + out_mat_dir <- paste0(output_dir,"/material") + if (!dir.exists(out_mat_dir)) { + dir.create(out_mat_dir) + } + file.copy(list.files(material_dir, full.names = TRUE), + out_mat_dir, + recursive = TRUE) + basic_docker <- .insert_material_dir(basic_docker) + } + } writeLines(basic_docker, file.path(output_dir, "Dockerfile")) invisible(output_dir) } From db7a2d7e48adef3943aeac7cdac5bfc40e536220 Mon Sep 17 00:00:00 2001 From: schochastics Date: Fri, 10 Feb 2023 18:13:31 +0100 Subject: [PATCH 2/2] material -> materials --- DESCRIPTION | 2 +- R/installation.R | 24 ++++++++++++------------ man/dockerize.Rd | 3 +++ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a9e903b..5535314 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,7 +10,7 @@ Description: Resolve the dependency graph of R packages at a specific time point License: GPL (>= 3) Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 Suggests: testthat (>= 3.0.0) Config/testthat/edition: 3 diff --git a/R/installation.R b/R/installation.R index a47b3cf..aae2131 100644 --- a/R/installation.R +++ b/R/installation.R @@ -161,14 +161,14 @@ basic_docker[gran_line:length(basic_docker)]) } -.insert_material_dir <- function(basic_docker){ +.insert_materials_dir <- function(basic_docker){ gran_line <- which(basic_docker == "COPY gran.R ./gran.R") c(basic_docker[1:gran_line], - "COPY material/ ./material/", + "COPY materials/ ./materials/", basic_docker[(gran_line+1):length(basic_docker)]) } -.generate_pre310_docker <- function(material_dir,r_version, debian_version = "lenny", lib, sysreps_cmd, cache) { +.generate_pre310_docker <- function(materials_dir,r_version, debian_version = "lenny", lib, sysreps_cmd, cache) { basic_docker <- c( paste0("FROM debian/eol:", debian_version), "ENV TZ UTC", @@ -257,7 +257,7 @@ export_granlist <- function(granlist, path, granlist_as_comment = TRUE, verbose #' This function exports the result from [resolve()] to a Docker file. For R version >= 3.1.0, the Dockerfile is based on the versioned Rocker image. #' For R version < 3.1.0, the Dockerfile is based on Debian and it compiles R from source. #' @param output_dir where to put the Docker file -#' @param material_dir additional resources (e.g. analysis scripts) to be copied into `output_dir` +#' @param materials_dir additional resources (e.g. analysis scripts) to be copied into `output_dir` #' @param image character, which versioned Rocker image to use. Can only be "r-ver", "rstudio", "tidyverse", "verse", "geospatial". #' This applies only to R version <= 3.1 #' @param cache logical, whether to cache the content from CRAN now. Please note that the system requirements are not cached @@ -278,7 +278,7 @@ export_granlist <- function(granlist, path, granlist_as_comment = TRUE, verbose #' } #' } #' @export -dockerize <- function(granlist, output_dir, material_dir = NULL, image = c("r-ver", "rstudio", "tidyverse", "verse", "geospatial"), +dockerize <- function(granlist, output_dir, materials_dir = NULL, image = c("r-ver", "rstudio", "tidyverse", "verse", "geospatial"), granlist_as_comment = TRUE, cache = FALSE, verbose = TRUE, lib = NA, cran_mirror = "https://cran.r-project.org/", check_cran_mirror = TRUE) { if (missing(output_dir)) { @@ -305,7 +305,7 @@ dockerize <- function(granlist, output_dir, material_dir = NULL, image = c("r-ve if (utils::compareVersion(granlist$r_version, "3.1") == -1) { file.copy(system.file("compile_r.sh", package = "gran"), file.path(output_dir, "compile_r.sh"), overwrite = TRUE) - basic_docker <- .generate_pre310_docker(material_dir, r_version = granlist$r_version, + basic_docker <- .generate_pre310_docker(materials_dir, r_version = granlist$r_version, sysreps_cmd = sysreps_cmd, lib = lib, cache = cache) } else { @@ -323,18 +323,18 @@ dockerize <- function(granlist, output_dir, material_dir = NULL, image = c("r-ve basic_docker <- .insert_cache_dir(basic_docker) } } - if(!is.null(material_dir)){ - if(!dir.exists(material_dir)){ - stop(paste0("The folder ",material_dir," does not exist"),call. = FALSE) + if(!is.null(materials_dir)){ + if(!dir.exists(materials_dir)){ + stop(paste0("The folder ",materials_dir," does not exist"),call. = FALSE) } else{ - out_mat_dir <- paste0(output_dir,"/material") + out_mat_dir <- paste0(output_dir,"/materials") if (!dir.exists(out_mat_dir)) { dir.create(out_mat_dir) } - file.copy(list.files(material_dir, full.names = TRUE), + file.copy(list.files(materials_dir, full.names = TRUE), out_mat_dir, recursive = TRUE) - basic_docker <- .insert_material_dir(basic_docker) + basic_docker <- .insert_materials_dir(basic_docker) } } writeLines(basic_docker, file.path(output_dir, "Dockerfile")) diff --git a/man/dockerize.Rd b/man/dockerize.Rd index 366194a..230af0c 100644 --- a/man/dockerize.Rd +++ b/man/dockerize.Rd @@ -10,6 +10,7 @@ dockerize( granlist, output_dir, + materials_dir = NULL, image = c("r-ver", "rstudio", "tidyverse", "verse", "geospatial"), granlist_as_comment = TRUE, cache = FALSE, @@ -30,6 +31,8 @@ dockerise_granlist(...) \item{output_dir}{where to put the Docker file} +\item{materials_dir}{additional resources (e.g. analysis scripts) to be copied into \code{output_dir}} + \item{image}{character, which versioned Rocker image to use. Can only be "r-ver", "rstudio", "tidyverse", "verse", "geospatial". This applies only to R version <= 3.1}