diff --git a/NEWS.md b/NEWS.md index c81ec11d..48fda94a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,6 +12,14 @@ manifest created for an renv project references the `renv.lock` in the `manifest.json`. (#926) +* Use the environment variable `RSCONNECT_PACKRAT` to analyze dependencies + using packrat, as was done prior to rsconnect-1.0.0. Use of the + `rsconnect.packrat` option is discouraged, as it is not effective when using + push-button deployment in the RStudio IDE. (#935) + +* The `renv.lock` is ignored when the `RSCONNECT_PACKRAT` environment variable + or the `rsconnect.packrat` option is set. (#936) + # rsconnect 1.0.1 * `deployDoc()` includes `.Rprofile`, `requirements.txt` and `renv.lock` when diff --git a/R/bundlePackage.R b/R/bundlePackage.R index cad17ed4..54fa0a1f 100644 --- a/R/bundlePackage.R +++ b/R/bundlePackage.R @@ -29,12 +29,26 @@ bundlePackages <- function(bundleDir, packages_list } +usePackrat <- function() { + # Use RSCONNECT_PACKRAT when it has any value; fall-back to rsconnect.packrat when the environment + # variable is unset. + env_value <- Sys.getenv("RSCONNECT_PACKRAT", unset = NA) + if (is.na(env_value)) { + return(isTRUE(getOption("rsconnect.packrat", FALSE))) + } + + return(truthy(env_value)) +} + computePackageDependencies <- function(bundleDir, extraPackages = character(), quiet = FALSE, verbose = FALSE) { - if (file.exists(renvLockFile(bundleDir))) { + if (usePackrat()) { + taskStart(quiet, "Capturing R dependencies with packrat") + deps <- snapshotPackratDependencies(bundleDir, extraPackages, verbose = verbose) + } else if (file.exists(renvLockFile(bundleDir))) { # This ignores extraPackages; if you're using a lockfile it's your # responsibility to install any other packages you need taskStart(quiet, "Capturing R dependencies from renv.lock") @@ -42,13 +56,10 @@ computePackageDependencies <- function(bundleDir, # Once we've captured the deps, we can remove the renv directory # from the bundle (retaining the renv.lock). removeRenv(bundleDir, lockfile = FALSE) - } else if (isFALSE(getOption("rsconnect.packrat", FALSE))) { + } else { taskStart(quiet, "Capturing R dependencies with renv") # TODO: give user option to choose between implicit and explicit deps <- snapshotRenvDependencies(bundleDir, extraPackages, verbose = verbose) - } else { - taskStart(quiet, "Capturing R dependencies with packrat") - deps <- snapshotPackratDependencies(bundleDir, extraPackages, verbose = verbose) } taskComplete(quiet, "Found {nrow(deps)} dependenc{?y/ies}") diff --git a/R/utils.R b/R/utils.R index 56b97f02..261a8cfe 100644 --- a/R/utils.R +++ b/R/utils.R @@ -161,3 +161,16 @@ toJSON <- function(x, ...) { ... ) } + +truthy <- function(value, default = FALSE) { + if (length(value) == 0) + default + else if (is.character(value)) + value %in% c("TRUE", "True", "true", "T", "1") + else if (is.symbol(value)) + as.character(value) %in% c("TRUE", "True", "true", "T", "1") + else if (is.na(value)) + default + else + as.logical(value) +}