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

Allow package version designation for CRAN packages w/ estimator #310

Merged
merged 13 commits into from
Apr 9, 2020
19 changes: 16 additions & 3 deletions R/environment.R
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,23 @@ generate_docker_file <- function(custom_docker_image = NULL,

if (!is.null(cran_packages)) {
for (package in cran_packages) {

# parse to split package name from version, if version provided
diondrapeck marked this conversation as resolved.
Show resolved Hide resolved
package_info <- strsplit(package, "==")[[1]]
package_name <- package_info[1]
version <- NULL

if (length(package_info) == 2) {
version <- sprintf(" version = \'%s\',", package_info[2])
}

base_dockerfile <- paste0(
base_dockerfile,
sprintf("RUN R -e \"install.packages(\'%s\', ", package),
"repos = \'https://cloud.r-project.org/\')\"\n")
base_dockerfile,
paste0(sprintf("RUN R -e \"remotes::install_version(\'%s\',",
package_name),
version,
" repos = \'https://cloud.r-project.org/\')\"\n")
)
}
}

Expand Down
7 changes: 7 additions & 0 deletions R/estimator.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@
#' objects to use as input.
#' @return The `Estimator` object.
#' @export
#' @section Examples:
#' ```
#' est <- estimator(source_directory = ".",
#' entry_script = "train.R",
#' cran_packages = c("ggplot2==3.3.0", "stringr"),
#' compute_target = compute_target)
#' ```
#' @seealso
#' \code{\link{r_environment}}
#' \code{\link{container_registry}}
Expand Down
12 changes: 12 additions & 0 deletions man/estimator.Rd

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

16 changes: 12 additions & 4 deletions tests/testthat/test_environment.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,22 @@ test_that("create dockerfile", {
", repos = 'https://cloud.r-project.org/', ",
"upgrade = FALSE)\"\n"))

# cran packages
# cran packages w/o version
dockerfile <- generate_docker_file(custom_docker_image = "ubuntu-18.04",
cran_packages = c("ggplot2"),
install_system_packages = FALSE)
expect_equal(dockerfile, paste0("FROM ubuntu-18.04\nRUN R -e \"install.",
"packages('ggplot2', repos = \'https://",
expect_equal(dockerfile, paste0("FROM ubuntu-18.04\nRUN R -e \"remotes::install_version",
"('ggplot2', repos = \'https://",
"cloud.r-project.org/\')\"\n"))


# cran packages w/ version
dockerfile <- generate_docker_file(custom_docker_image = "ubuntu-18.04",
cran_packages = c("ggplot2==0.0.0"),
install_system_packages = FALSE)
expect_equal(dockerfile, paste0("FROM ubuntu-18.04\nRUN R -e \"remotes::install_version",
"('ggplot2', version = '0.0.0', repos = \'https://",
"cloud.r-project.org/\')\"\n"))

# github packages
dockerfile <- generate_docker_file(github_packages = c(
"https://github/user/repo1",
Expand Down