diff --git a/NEWS.md b/NEWS.md index d88a36461..f69731a52 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,9 @@ # renv 1.1.0 (UNRELEASED) +* Fixed an issue where `renv` library paths were not properly reset following + a suspend / resume in RStudio Server. (#2036) + * `renv::run()` gains the `args` parameter, which can be used to pass command-line arguments to a script. (#2015) diff --git a/R/project.R b/R/project.R index c94d6862f..8f4dd1ac4 100644 --- a/R/project.R +++ b/R/project.R @@ -32,15 +32,19 @@ renv_project_get <- function(default = NULL) { the$project_path %||% default } -# NOTE: RENV_PROJECT kept for backwards compatibility with RStudio +# NOTE: 'RENV_PROJECT' kept for backwards compatibility with RStudio renv_project_set <- function(project) { the$project_path <- project + # https://github.com/rstudio/renv/issues/2036 + options(renv.project.path = project) Sys.setenv(RENV_PROJECT = project) } # NOTE: 'RENV_PROJECT' kept for backwards compatibility with RStudio renv_project_clear <- function() { the$project_path <- NULL + # https://github.com/rstudio/renv/issues/2036 + options(renv.project.path = NULL) Sys.unsetenv("RENV_PROJECT") } diff --git a/R/zzz.R b/R/zzz.R index cd211aa7c..faf8025e4 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -59,11 +59,16 @@ # if an renv project already appears to be loaded, then re-activate # the sandbox now -- this is primarily done to support suspend and - # resume with RStudio where the user profile might not be run + # resume with RStudio where the user profile might not have been run, + # but RStudio would have restored options from the prior session + # + # https://github.com/rstudio/renv/issues/2036 if (renv_rstudio_available()) { project <- getOption("renv.project.path") - if (!is.null(project)) + if (!is.null(project)) { + renv_project_set(project) renv_sandbox_activate(project = project) + } } # make sure renv is unloaded on exit, so locks etc. are released