Skip to content

Commit

Permalink
prefer RSCONNECT_PACKRAT over rsconnect.packrat
Browse files Browse the repository at this point in the history
Environment variables are visible in the RStudio IDE R session used for
push-button deployment. Not all R options are mirrored into that session.

Fixes #935
Fixes #936
  • Loading branch information
aronatkins committed Jul 27, 2023
1 parent 74a2cf7 commit 47249d5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 16 additions & 5 deletions R/bundlePackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,37 @@ 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")
deps <- parseRenvDependencies(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}")

Expand Down
13 changes: 13 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 47249d5

Please sign in to comment.