Skip to content

Commit 060298d

Browse files
committed
upate renv
1 parent ac1a9e5 commit 060298d

File tree

1 file changed

+45
-25
lines changed

1 file changed

+45
-25
lines changed

renv/activate.R

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,27 @@
22
local({
33

44
# the requested version of renv
5-
version <- "1.0.0"
5+
version <- "1.0.1"
66
attr(version, "sha") <- NULL
77

88
# the project directory
99
project <- getwd()
1010

11+
# use start-up diagnostics if enabled
12+
diagnostics <- Sys.getenv("RENV_STARTUP_DIAGNOSTICS", unset = "FALSE")
13+
if (diagnostics) {
14+
start <- Sys.time()
15+
profile <- tempfile("renv-startup-", fileext = ".Rprof")
16+
utils::Rprof(profile)
17+
on.exit({
18+
utils::Rprof(NULL)
19+
elapsed <- signif(difftime(Sys.time(), start, units = "auto"), digits = 2L)
20+
writeLines(sprintf("- renv took %s to run the autoloader.", format(elapsed)))
21+
writeLines(sprintf("- Profile: %s", profile))
22+
print(utils::summaryRprof(profile))
23+
}, add = TRUE)
24+
}
25+
1126
# figure out whether the autoloader is enabled
1227
enabled <- local({
1328

@@ -504,7 +519,7 @@ local({
504519

505520
# open the bundle for reading
506521
# We use gzcon for everything because (from ?gzcon)
507-
# > Reading from a connection which does not supply a gzip magic
522+
# > Reading from a connection which does not supply a 'gzip' magic
508523
# > header is equivalent to reading from the original connection
509524
conn <- gzcon(file(bundle, open = "rb", raw = TRUE))
510525
on.exit(close(conn))
@@ -767,10 +782,12 @@ local({
767782
renv_bootstrap_validate_version <- function(version, description = NULL) {
768783

769784
# resolve description file
770-
description <- description %||% {
771-
path <- getNamespaceInfo("renv", "path")
772-
packageDescription("renv", lib.loc = dirname(path))
773-
}
785+
#
786+
# avoid passing lib.loc to `packageDescription()` below, since R will
787+
# use the loaded version of the package by default anyhow. note that
788+
# this function should only be called after 'renv' is loaded
789+
# https://github.com/rstudio/renv/issues/1625
790+
description <- description %||% packageDescription("renv")
774791

775792
# check whether requested version 'version' matches loaded version of renv
776793
sha <- attr(version, "sha", exact = TRUE)
@@ -841,7 +858,7 @@ local({
841858
hooks <- getHook("renv::autoload")
842859
for (hook in hooks)
843860
if (is.function(hook))
844-
tryCatch(hook(), error = warning)
861+
tryCatch(hook(), error = warnify)
845862

846863
# load the project
847864
renv::load(project)
@@ -982,10 +999,15 @@ local({
982999

9831000
}
9841001

985-
renv_bootstrap_version_friendly <- function(version, sha = NULL) {
1002+
renv_bootstrap_version_friendly <- function(version, shafmt = NULL, sha = NULL) {
9861003
sha <- sha %||% attr(version, "sha", exact = TRUE)
987-
parts <- c(version, sprintf("[sha: %s]", substring(sha, 1L, 7L)))
988-
paste(parts, collapse = " ")
1004+
parts <- c(version, sprintf(shafmt %||% " [sha: %s]", substring(sha, 1L, 7L)))
1005+
paste(parts, collapse = "")
1006+
}
1007+
1008+
renv_bootstrap_exec <- function(project, libpath, version) {
1009+
if (!renv_bootstrap_load(project, libpath, version))
1010+
renv_bootstrap_run(version, libpath)
9891011
}
9901012

9911013
renv_bootstrap_run <- function(version, libpath) {
@@ -1017,6 +1039,14 @@ local({
10171039
commandArgs()[[1]] == "RStudio"
10181040
}
10191041

1042+
# Used to work around buglet in RStudio if hook uses readline
1043+
renv_bootstrap_flush_console <- function() {
1044+
tryCatch({
1045+
tools <- as.environment("tools:rstudio")
1046+
tools$.rs.api.sendToConsole("", echo = FALSE, focus = FALSE)
1047+
}, error = function(cnd) {})
1048+
}
1049+
10201050
renv_json_read <- function(file = NULL, text = NULL) {
10211051

10221052
jlerr <- NULL
@@ -1155,25 +1185,15 @@ local({
11551185
# construct full libpath
11561186
libpath <- file.path(root, prefix)
11571187

1158-
# attempt to load
1159-
if (renv_bootstrap_load(project, libpath, version))
1160-
return(TRUE)
1161-
11621188
if (renv_bootstrap_in_rstudio()) {
1189+
# RStudio only updates console once .Rprofile is finished, so
1190+
# instead run code on sessionInit
11631191
setHook("rstudio.sessionInit", function(...) {
1164-
renv_bootstrap_run(version, libpath)
1165-
1166-
# Work around buglet in RStudio if hook uses readline
1167-
tryCatch(
1168-
{
1169-
tools <- as.environment("tools:rstudio")
1170-
tools$.rs.api.sendToConsole("", echo = FALSE, focus = FALSE)
1171-
},
1172-
error = function(cnd) {}
1173-
)
1192+
renv_bootstrap_exec(project, libpath, version)
1193+
renv_bootstrap_flush_console()
11741194
})
11751195
} else {
1176-
renv_bootstrap_run(version, libpath)
1196+
renv_bootstrap_exec(project, libpath, version)
11771197
}
11781198

11791199
invisible()

0 commit comments

Comments
 (0)