|
2 | 2 | local({
|
3 | 3 |
|
4 | 4 | # the requested version of renv
|
5 |
| - version <- "1.0.0" |
| 5 | + version <- "1.0.1" |
6 | 6 | attr(version, "sha") <- NULL
|
7 | 7 |
|
8 | 8 | # the project directory
|
9 | 9 | project <- getwd()
|
10 | 10 |
|
| 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 | + |
11 | 26 | # figure out whether the autoloader is enabled
|
12 | 27 | enabled <- local({
|
13 | 28 |
|
@@ -504,7 +519,7 @@ local({
|
504 | 519 |
|
505 | 520 | # open the bundle for reading
|
506 | 521 | # 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 |
508 | 523 | # > header is equivalent to reading from the original connection
|
509 | 524 | conn <- gzcon(file(bundle, open = "rb", raw = TRUE))
|
510 | 525 | on.exit(close(conn))
|
@@ -767,10 +782,12 @@ local({
|
767 | 782 | renv_bootstrap_validate_version <- function(version, description = NULL) {
|
768 | 783 |
|
769 | 784 | # 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") |
774 | 791 |
|
775 | 792 | # check whether requested version 'version' matches loaded version of renv
|
776 | 793 | sha <- attr(version, "sha", exact = TRUE)
|
@@ -841,7 +858,7 @@ local({
|
841 | 858 | hooks <- getHook("renv::autoload")
|
842 | 859 | for (hook in hooks)
|
843 | 860 | if (is.function(hook))
|
844 |
| - tryCatch(hook(), error = warning) |
| 861 | + tryCatch(hook(), error = warnify) |
845 | 862 |
|
846 | 863 | # load the project
|
847 | 864 | renv::load(project)
|
@@ -982,10 +999,15 @@ local({
|
982 | 999 |
|
983 | 1000 | }
|
984 | 1001 |
|
985 |
| - renv_bootstrap_version_friendly <- function(version, sha = NULL) { |
| 1002 | + renv_bootstrap_version_friendly <- function(version, shafmt = NULL, sha = NULL) { |
986 | 1003 | 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) |
989 | 1011 | }
|
990 | 1012 |
|
991 | 1013 | renv_bootstrap_run <- function(version, libpath) {
|
@@ -1017,6 +1039,14 @@ local({
|
1017 | 1039 | commandArgs()[[1]] == "RStudio"
|
1018 | 1040 | }
|
1019 | 1041 |
|
| 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 | + |
1020 | 1050 | renv_json_read <- function(file = NULL, text = NULL) {
|
1021 | 1051 |
|
1022 | 1052 | jlerr <- NULL
|
@@ -1155,25 +1185,15 @@ local({
|
1155 | 1185 | # construct full libpath
|
1156 | 1186 | libpath <- file.path(root, prefix)
|
1157 | 1187 |
|
1158 |
| - # attempt to load |
1159 |
| - if (renv_bootstrap_load(project, libpath, version)) |
1160 |
| - return(TRUE) |
1161 |
| - |
1162 | 1188 | if (renv_bootstrap_in_rstudio()) {
|
| 1189 | + # RStudio only updates console once .Rprofile is finished, so |
| 1190 | + # instead run code on sessionInit |
1163 | 1191 | 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() |
1174 | 1194 | })
|
1175 | 1195 | } else {
|
1176 |
| - renv_bootstrap_run(version, libpath) |
| 1196 | + renv_bootstrap_exec(project, libpath, version) |
1177 | 1197 | }
|
1178 | 1198 |
|
1179 | 1199 | invisible()
|
|
0 commit comments