Skip to content

Commit

Permalink
Merge pull request #428 from datacarpentry/update/packages
Browse files Browse the repository at this point in the history
Update 45 packages
  • Loading branch information
drakeasberry authored Mar 24, 2024
2 parents e018b34 + ee4868d commit dde91e6
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 137 deletions.
64 changes: 32 additions & 32 deletions renv/activate.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
local({

# the requested version of renv
version <- "1.0.2"
version <- "1.0.5"
attr(version, "sha") <- NULL

# the project directory
Expand Down Expand Up @@ -31,6 +31,14 @@ local({
if (!is.null(override))
return(override)

# if we're being run in a context where R_LIBS is already set,
# don't load -- presumably we're being run as a sub-process and
# the parent process has already set up library paths for us
rcmd <- Sys.getenv("R_CMD", unset = NA)
rlibs <- Sys.getenv("R_LIBS", unset = NA)
if (!is.na(rlibs) && !is.na(rcmd))
return(FALSE)

# next, check environment variables
# TODO: prefer using the configuration one in the future
envvars <- c(
Expand All @@ -50,9 +58,22 @@ local({

})

if (!enabled)
# bail if we're not enabled
if (!enabled) {

# if we're not enabled, we might still need to manually load
# the user profile here
profile <- Sys.getenv("R_PROFILE_USER", unset = "~/.Rprofile")
if (file.exists(profile)) {
cfg <- Sys.getenv("RENV_CONFIG_USER_PROFILE", unset = "TRUE")
if (tolower(cfg) %in% c("true", "t", "1"))
sys.source(profile, envir = globalenv())
}

return(FALSE)

}

# avoid recursion
if (identical(getOption("renv.autoloader.running"), TRUE)) {
warning("ignoring recursive attempt to run renv autoloader")
Expand Down Expand Up @@ -1034,27 +1055,14 @@ 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

# if jsonlite is loaded, use that instead
if ("jsonlite" %in% loadedNamespaces()) {

json <- catch(renv_json_read_jsonlite(file, text))
json <- tryCatch(renv_json_read_jsonlite(file, text), error = identity)
if (!inherits(json, "error"))
return(json)

Expand All @@ -1063,7 +1071,7 @@ local({
}

# otherwise, fall back to the default JSON reader
json <- catch(renv_json_read_default(file, text))
json <- tryCatch(renv_json_read_default(file, text), error = identity)
if (!inherits(json, "error"))
return(json)

Expand All @@ -1076,14 +1084,14 @@ local({
}

renv_json_read_jsonlite <- function(file = NULL, text = NULL) {
text <- paste(text %||% read(file), collapse = "\n")
text <- paste(text %||% readLines(file, warn = FALSE), collapse = "\n")
jsonlite::fromJSON(txt = text, simplifyVector = FALSE)
}

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

# find strings in the JSON
text <- paste(text %||% read(file), collapse = "\n")
text <- paste(text %||% readLines(file, warn = FALSE), collapse = "\n")
pattern <- '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
locs <- gregexpr(pattern, text, perl = TRUE)[[1]]

Expand Down Expand Up @@ -1131,14 +1139,14 @@ local({
map <- as.list(map)

# remap strings in object
remapped <- renv_json_remap(json, map)
remapped <- renv_json_read_remap(json, map)

# evaluate
eval(remapped, envir = baseenv())

}

renv_json_remap <- function(json, map) {
renv_json_read_remap <- function(json, map) {

# fix names
if (!is.null(names(json))) {
Expand All @@ -1165,7 +1173,7 @@ local({
# recurse
if (is.recursive(json)) {
for (i in seq_along(json)) {
json[i] <- list(renv_json_remap(json[[i]], map))
json[i] <- list(renv_json_read_remap(json[[i]], map))
}
}

Expand All @@ -1185,16 +1193,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
Loading

0 comments on commit dde91e6

Please sign in to comment.