Skip to content

Commit dde91e6

Browse files
authored
Merge pull request #428 from datacarpentry/update/packages
Update 45 packages
2 parents e018b34 + ee4868d commit dde91e6

File tree

2 files changed

+140
-137
lines changed

2 files changed

+140
-137
lines changed

renv/activate.R

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
local({
33

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

88
# the project directory
@@ -31,6 +31,14 @@ local({
3131
if (!is.null(override))
3232
return(override)
3333

34+
# if we're being run in a context where R_LIBS is already set,
35+
# don't load -- presumably we're being run as a sub-process and
36+
# the parent process has already set up library paths for us
37+
rcmd <- Sys.getenv("R_CMD", unset = NA)
38+
rlibs <- Sys.getenv("R_LIBS", unset = NA)
39+
if (!is.na(rlibs) && !is.na(rcmd))
40+
return(FALSE)
41+
3442
# next, check environment variables
3543
# TODO: prefer using the configuration one in the future
3644
envvars <- c(
@@ -50,9 +58,22 @@ local({
5058

5159
})
5260

53-
if (!enabled)
61+
# bail if we're not enabled
62+
if (!enabled) {
63+
64+
# if we're not enabled, we might still need to manually load
65+
# the user profile here
66+
profile <- Sys.getenv("R_PROFILE_USER", unset = "~/.Rprofile")
67+
if (file.exists(profile)) {
68+
cfg <- Sys.getenv("RENV_CONFIG_USER_PROFILE", unset = "TRUE")
69+
if (tolower(cfg) %in% c("true", "t", "1"))
70+
sys.source(profile, envir = globalenv())
71+
}
72+
5473
return(FALSE)
5574

75+
}
76+
5677
# avoid recursion
5778
if (identical(getOption("renv.autoloader.running"), TRUE)) {
5879
warning("ignoring recursive attempt to run renv autoloader")
@@ -1034,27 +1055,14 @@ local({
10341055

10351056
}
10361057

1037-
1038-
renv_bootstrap_in_rstudio <- function() {
1039-
commandArgs()[[1]] == "RStudio"
1040-
}
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-
10501058
renv_json_read <- function(file = NULL, text = NULL) {
10511059

10521060
jlerr <- NULL
10531061

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

1057-
json <- catch(renv_json_read_jsonlite(file, text))
1065+
json <- tryCatch(renv_json_read_jsonlite(file, text), error = identity)
10581066
if (!inherits(json, "error"))
10591067
return(json)
10601068

@@ -1063,7 +1071,7 @@ local({
10631071
}
10641072

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

@@ -1076,14 +1084,14 @@ local({
10761084
}
10771085

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

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

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

@@ -1131,14 +1139,14 @@ local({
11311139
map <- as.list(map)
11321140

11331141
# remap strings in object
1134-
remapped <- renv_json_remap(json, map)
1142+
remapped <- renv_json_read_remap(json, map)
11351143

11361144
# evaluate
11371145
eval(remapped, envir = baseenv())
11381146

11391147
}
11401148

1141-
renv_json_remap <- function(json, map) {
1149+
renv_json_read_remap <- function(json, map) {
11421150

11431151
# fix names
11441152
if (!is.null(names(json))) {
@@ -1165,7 +1173,7 @@ local({
11651173
# recurse
11661174
if (is.recursive(json)) {
11671175
for (i in seq_along(json)) {
1168-
json[i] <- list(renv_json_remap(json[[i]], map))
1176+
json[i] <- list(renv_json_read_remap(json[[i]], map))
11691177
}
11701178
}
11711179

@@ -1185,16 +1193,8 @@ local({
11851193
# construct full libpath
11861194
libpath <- file.path(root, prefix)
11871195

1188-
if (renv_bootstrap_in_rstudio()) {
1189-
# RStudio only updates console once .Rprofile is finished, so
1190-
# instead run code on sessionInit
1191-
setHook("rstudio.sessionInit", function(...) {
1192-
renv_bootstrap_exec(project, libpath, version)
1193-
renv_bootstrap_flush_console()
1194-
})
1195-
} else {
1196-
renv_bootstrap_exec(project, libpath, version)
1197-
}
1196+
# run bootstrap code
1197+
renv_bootstrap_exec(project, libpath, version)
11981198

11991199
invisible()
12001200

0 commit comments

Comments
 (0)