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 flag to dock_from_renv function #60

Merged
merged 3 commits into from
Oct 29, 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
22 changes: 20 additions & 2 deletions R/dock_from_renv.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ available_distros <- c(
#' @param repos character. The URL(s) of the repositories to use for `options("repos")`.
#' @param extra_sysreqs character vector. Extra debian system requirements.
#' Will be installed with apt-get install.
#' @param keep_renv_version boolean. If `TRUE` the version of renv in the lockfile
#' will be used for the `renv::restore()` command
#' @importFrom utils getFromNamespace
#' @return A R6 object of class `Dockerfile`.
#' @details
Expand Down Expand Up @@ -52,7 +54,8 @@ dock_from_renv <- function(
sysreqs = TRUE,
repos = c(CRAN = "https://cran.rstudio.com/"),
expand = FALSE,
extra_sysreqs = NULL
extra_sysreqs = NULL,
keep_renv_version = FALSE
) {
distro <- match.arg(distro, available_distros)

Expand All @@ -72,6 +75,9 @@ dock_from_renv <- function(
AS = AS
)

# get renv version
renv_version <- lock$data()$Packages$renv$Version

distro_args <- switch(
distro,
centos7 = list(
Expand Down Expand Up @@ -235,7 +241,19 @@ dock_from_renv <- function(
)
)

dock$RUN("R -e 'install.packages(c(\"renv\",\"remotes\"))'")
# check if keep_renv_version is true
if (keep_renv_version){
dock$RUN("R -e 'install.packages(\"remotes\")'")
install_renv_string <- paste0(
"R -e 'remotes::install_version(\"renv\", version = ",
renv_version,
")'"
)
dock$RUN(install_renv_string)

} else {
dock$RUN("R -e 'install.packages(c(\"renv\",\"remotes\"))'")
}

dock$COPY(basename(lockfile), "renv.lock")
dock$RUN(r(renv::restore()))
Expand Down
30 changes: 30 additions & 0 deletions tests/testthat/test-dock_from_renv.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,36 @@ renv_file <- readLines(file.path(dir_build, "renv.lock"))
renv_file[grep("Version", renv_file)[1]] <- ' "Version": "4.1.2",'
writeLines(renv_file, file.path(dir_build, "renv.lock"))

test_that("dock_from_renv works with old renv", {
out <- dock_from_renv(
lockfile = the_lockfile,
distro = "focal",
FROM = "rocker/verse",
keep_renv_version = TRUE
)

out$write(
file.path(
dir_build,
"Dockerfile"
)
)

dock_created <- readLines(
file.path(
dir_build,
"Dockerfile"
)
)

test_string <- "remotes::install.version\\(\"renv\", version = 1.0.2\\)"
message(test_string)
expect_length(
grep(test_string , dock_created), 1
)

})

# dock_from_renv ----
test_that("dock_from_renv works", {
# skip_if_not(interactive())
Expand Down
Loading