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

fix issue with autoloader in RStudio #1652

Merged
merged 1 commit into from
Aug 16, 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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# renv (development version)

* Fixed an issue that could cause code within a project `.Rprofile` to execute
before the project had been loaded in RStudio. (#1650)

* `renv::snapshot()` and `renv::status()` gain the `dev` argument. This
can be used when you'd like to capture package dependencies from
the *Suggests* field of your package's DESCRIPTION file. (#1019)
Expand Down
13 changes: 0 additions & 13 deletions R/bootstrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -957,16 +957,3 @@ renv_bootstrap_run <- function(version, libpath) {
warning(paste(msg, collapse = "\n"), call. = FALSE)

}


renv_bootstrap_in_rstudio <- function() {
commandArgs()[[1]] == "RStudio"
}

# Used to work around buglet in RStudio if hook uses readline
renv_bootstrap_flush_console <- function() {
tryCatch({
tools <- as.environment("tools:rstudio")
tools$.rs.api.sendToConsole("", echo = FALSE, focus = FALSE)
}, error = function(cnd) {})
}
15 changes: 13 additions & 2 deletions R/load.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,23 @@ renv_load_action <- function(project) {
if (!interactive())
return("load")

# if this project doesn't yet contain an 'renv' folder, assume
# that it has not yet been initialized, and prompt the user
# if this project already contains an 'renv' folder, assume it's
# already been initialized and we can directly load it
renv <- renv_paths_renv(project = project, profile = FALSE)
if (dir.exists(renv))
return("load")

# if we're running within RStudio at this point, and we're running
# within the auto-loader, we need to defer execution here so that
# the console is able to properly receive user input and update
# https://github.com/rstudio/renv/issues/1650
autoloading <- getOption("renv.autoloader.running", default = FALSE)
if (autoloading && renv_rstudio_available()) {
setHook("rstudio.sessionInit", function() {
renv::load(project)
})
}

# check and see if we're being called within a sub-directory
path <- renv_file_find(dirname(project), function(parent) {
if (file.exists(file.path(parent, "renv")))
Expand Down
25 changes: 2 additions & 23 deletions inst/resources/activate.R
Original file line number Diff line number Diff line change
Expand Up @@ -1034,19 +1034,6 @@ local({

}


renv_bootstrap_in_rstudio <- function() {
commandArgs()[[1]] == "RStudio"
}

# Used to work around buglet in RStudio if hook uses readline
renv_bootstrap_flush_console <- function() {
tryCatch({
tools <- as.environment("tools:rstudio")
tools$.rs.api.sendToConsole("", echo = FALSE, focus = FALSE)
}, error = function(cnd) {})
}

renv_json_read <- function(file = NULL, text = NULL) {

jlerr <- NULL
Expand Down Expand Up @@ -1185,16 +1172,8 @@ local({
# construct full libpath
libpath <- file.path(root, prefix)

if (renv_bootstrap_in_rstudio()) {
# RStudio only updates console once .Rprofile is finished, so
# instead run code on sessionInit
setHook("rstudio.sessionInit", function(...) {
renv_bootstrap_exec(project, libpath, version)
renv_bootstrap_flush_console()
})
} else {
renv_bootstrap_exec(project, libpath, version)
}
# run bootstrap code
renv_bootstrap_exec(project, libpath, version)

invisible()

Expand Down
12 changes: 2 additions & 10 deletions templates/template-activate.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,8 @@ local({
# construct full libpath
libpath <- file.path(root, prefix)

if (renv_bootstrap_in_rstudio()) {
# RStudio only updates console once .Rprofile is finished, so
# instead run code on sessionInit
setHook("rstudio.sessionInit", function(...) {
renv_bootstrap_exec(project, libpath, version)
renv_bootstrap_flush_console()
})
} else {
renv_bootstrap_exec(project, libpath, version)
}
# run bootstrap code
renv_bootstrap_exec(project, libpath, version)

invisible()

Expand Down