major overhaul with new functions. docs are lacking

This commit is contained in:
Andreas Gammelgaard Damsbo 2024-05-02 13:31:21 +02:00
commit 04f5bec85c
No known key found for this signature in database
28 changed files with 874 additions and 81 deletions

View file

@ -2,11 +2,13 @@
local({
# the requested version of renv
version <- "1.0.5"
version <- "1.0.7"
attr(version, "sha") <- NULL
# the project directory
project <- getwd()
project <- Sys.getenv("RENV_PROJECT")
if (!nzchar(project))
project <- getwd()
# use start-up diagnostics if enabled
diagnostics <- Sys.getenv("RENV_STARTUP_DIAGNOSTICS", unset = "FALSE")
@ -129,6 +131,21 @@ local({
}
heredoc <- function(text, leave = 0) {
# remove leading, trailing whitespace
trimmed <- gsub("^\\s*\\n|\\n\\s*$", "", text)
# split into lines
lines <- strsplit(trimmed, "\n", fixed = TRUE)[[1L]]
# compute common indent
indent <- regexpr("[^[:space:]]", lines)
common <- min(setdiff(indent, -1L)) - leave
paste(substring(lines, common), collapse = "\n")
}
startswith <- function(string, prefix) {
substring(string, 1, nchar(prefix)) == prefix
}
@ -631,6 +648,9 @@ local({
# if the user has requested an automatic prefix, generate it
auto <- Sys.getenv("RENV_PATHS_PREFIX_AUTO", unset = NA)
if (is.na(auto) && getRversion() >= "4.4.0")
auto <- "TRUE"
if (auto %in% c("TRUE", "True", "true", "1"))
return(renv_bootstrap_platform_prefix_auto())
@ -822,24 +842,23 @@ local({
# the loaded version of renv doesn't match the requested version;
# give the user instructions on how to proceed
remote <- if (!is.null(description[["RemoteSha"]])) {
dev <- identical(description[["RemoteType"]], "github")
remote <- if (dev)
paste("rstudio/renv", description[["RemoteSha"]], sep = "@")
} else {
else
paste("renv", description[["Version"]], sep = "@")
}
# display both loaded version + sha if available
friendly <- renv_bootstrap_version_friendly(
version = description[["Version"]],
sha = description[["RemoteSha"]]
sha = if (dev) description[["RemoteSha"]]
)
fmt <- paste(
"renv %1$s was loaded from project library, but this project is configured to use renv %2$s.",
"- Use `renv::record(\"%3$s\")` to record renv %1$s in the lockfile.",
"- Use `renv::restore(packages = \"renv\")` to install renv %2$s into the project library.",
sep = "\n"
)
fmt <- heredoc("
renv %1$s was loaded from project library, but this project is configured to use renv %2$s.
- Use `renv::record(\"%3$s\")` to record renv %1$s in the lockfile.
- Use `renv::restore(packages = \"renv\")` to install renv %2$s into the project library.
")
catf(fmt, friendly, renv_bootstrap_version_friendly(version), remote)
FALSE