diff --git a/.Rprofile b/.Rprofile index 8499baf2..9df24088 100644 --- a/.Rprofile +++ b/.Rprofile @@ -22,11 +22,7 @@ Sys.setenv("RENV_CONFIG_AUTO_SNAPSHOT" = FALSE) # Do not load renv by default -if (identical(Sys.getenv("RENV_AUTOLOADER_ENABLED"), "")) { - Sys.setenv("RENV_AUTOLOADER_ENABLED" = FALSE) -} - -if (!isFALSE(Sys.getenv("RENV_AUTOLOADER_ENABLED"))) { +if (!(Sys.getenv("RENV_AUTOLOADER_ENABLED") %in% c("false", "FALSE"))) { .renv_profile <- paste(R.version$major, substr(R.version$minor, 1, 1), sep = ".") if (!file.exists("./renv/profile")) { if (.renv_profile %in% c("4.1", "4.2", "4.3")) { diff --git a/.lintr b/.lintr index a6fd5cfc..7335edbd 100644 --- a/.lintr +++ b/.lintr @@ -13,7 +13,6 @@ linters: linters_with_defaults( expect_true_false_linter(), expect_type_linter(), fixed_regex_linter(), - for_loop_index_linter(), implicit_assignment_linter(), implicit_integer_linter(), line_length_linter(120), diff --git a/.lycheeignore b/.lycheeignore index 4aa17b34..522c308a 100644 --- a/.lycheeignore +++ b/.lycheeignore @@ -1 +1,5 @@ https://cran.r-project.org/package=sdtm.oak +https://packagemanager.posit.co/cran/2023-03-15/ +https://packagemanager.posit.co/cran/2023-04-20/ +https://packagemanager.posit.co/cran/2022-03-10/ +https://packagemanager.posit.co/cran/latest/ diff --git a/renv/activate.R b/renv/activate.R index cc742fc9..5b5d38be 100644 --- a/renv/activate.R +++ b/renv/activate.R @@ -8,6 +8,21 @@ local({ # the project directory project <- getwd() + # use start-up diagnostics if enabled + diagnostics <- Sys.getenv("RENV_STARTUP_DIAGNOSTICS", unset = "FALSE") + if (diagnostics) { + start <- Sys.time() + profile <- tempfile("renv-startup-", fileext = ".Rprof") + utils::Rprof(profile) + on.exit({ + utils::Rprof(NULL) + elapsed <- signif(difftime(Sys.time(), start, units = "auto"), digits = 2L) + writeLines(sprintf("- renv took %s to run the autoloader.", format(elapsed))) + writeLines(sprintf("- Profile: %s", profile)) + print(utils::summaryRprof(profile)) + }, add = TRUE) + } + # figure out whether the autoloader is enabled enabled <- local({ @@ -504,7 +519,7 @@ local({ # open the bundle for reading # We use gzcon for everything because (from ?gzcon) - # > Reading from a connection which does not supply a ‘gzip’ magic + # > Reading from a connection which does not supply a 'gzip' magic # > header is equivalent to reading from the original connection conn <- gzcon(file(bundle, open = "rb", raw = TRUE)) on.exit(close(conn)) @@ -767,10 +782,12 @@ local({ renv_bootstrap_validate_version <- function(version, description = NULL) { # resolve description file - description <- description %||% { - path <- getNamespaceInfo("renv", "path") - packageDescription("renv", lib.loc = dirname(path)) - } + # + # avoid passing lib.loc to `packageDescription()` below, since R will + # use the loaded version of the package by default anyhow. note that + # this function should only be called after 'renv' is loaded + # https://github.com/rstudio/renv/issues/1625 + description <- description %||% packageDescription("renv") # check whether requested version 'version' matches loaded version of renv sha <- attr(version, "sha", exact = TRUE) @@ -841,7 +858,7 @@ local({ hooks <- getHook("renv::autoload") for (hook in hooks) if (is.function(hook)) - tryCatch(hook(), error = warning) + tryCatch(hook(), error = warnify) # load the project renv::load(project) @@ -982,10 +999,15 @@ local({ } - renv_bootstrap_version_friendly <- function(version, sha = NULL) { + renv_bootstrap_version_friendly <- function(version, shafmt = NULL, sha = NULL) { sha <- sha %||% attr(version, "sha", exact = TRUE) - parts <- c(version, sprintf("[sha: %s]", substring(sha, 1L, 7L))) - paste(parts, collapse = " ") + parts <- c(version, sprintf(shafmt %||% " [sha: %s]", substring(sha, 1L, 7L))) + paste(parts, collapse = "") + } + + renv_bootstrap_exec <- function(project, libpath, version) { + if (!renv_bootstrap_load(project, libpath, version)) + renv_bootstrap_run(version, libpath) } renv_bootstrap_run <- function(version, libpath) { @@ -1012,11 +1034,6 @@ local({ } - - renv_bootstrap_in_rstudio <- function() { - commandArgs()[[1]] == "RStudio" - } - renv_json_read <- function(file = NULL, text = NULL) { jlerr <- NULL @@ -1155,26 +1172,8 @@ local({ # construct full libpath libpath <- file.path(root, prefix) - # attempt to load - if (renv_bootstrap_load(project, libpath, version)) - return(TRUE) - - if (renv_bootstrap_in_rstudio()) { - setHook("rstudio.sessionInit", function(...) { - renv_bootstrap_run(version, libpath) - - # Work around buglet in RStudio if hook uses readline - tryCatch( - { - tools <- as.environment("tools:rstudio") - tools$.rs.api.sendToConsole("", echo = FALSE, focus = FALSE) - }, - error = function(cnd) {} - ) - }) - } else { - renv_bootstrap_run(version, libpath) - } + # run bootstrap code + renv_bootstrap_exec(project, libpath, version) invisible()