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

add materials (#23) #30

Merged
merged 2 commits into from
Feb 10, 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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 25 additions & 3 deletions R/installation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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_materials_dir <- function(basic_docker){
gran_line <- which(basic_docker == "COPY gran.R ./gran.R")
c(basic_docker[1:gran_line],
"COPY materials/ ./materials/",
basic_docker[(gran_line+1):length(basic_docker)])
}

.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",
Expand Down Expand Up @@ -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 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
Expand All @@ -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, 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)) {
Expand All @@ -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(materials_dir, r_version = granlist$r_version,
sysreps_cmd = sysreps_cmd, lib = lib,
cache = cache)
} else {
Expand All @@ -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(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,"/materials")
if (!dir.exists(out_mat_dir)) {
dir.create(out_mat_dir)
}
file.copy(list.files(materials_dir, full.names = TRUE),
out_mat_dir,
recursive = TRUE)
basic_docker <- .insert_materials_dir(basic_docker)
}
}
writeLines(basic_docker, file.path(output_dir, "Dockerfile"))
invisible(output_dir)
}
Expand Down
3 changes: 3 additions & 0 deletions man/dockerize.Rd

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