2
2
local({
3
3
4
4
# the requested version of renv
5
- version <- " 1.0.2 "
5
+ version <- " 1.0.5 "
6
6
attr(version , " sha" ) <- NULL
7
7
8
8
# the project directory
@@ -31,6 +31,14 @@ local({
31
31
if (! is.null(override ))
32
32
return (override )
33
33
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
+
34
42
# next, check environment variables
35
43
# TODO: prefer using the configuration one in the future
36
44
envvars <- c(
@@ -50,9 +58,22 @@ local({
50
58
51
59
})
52
60
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
+
54
73
return (FALSE )
55
74
75
+ }
76
+
56
77
# avoid recursion
57
78
if (identical(getOption(" renv.autoloader.running" ), TRUE )) {
58
79
warning(" ignoring recursive attempt to run renv autoloader" )
@@ -1034,27 +1055,14 @@ local({
1034
1055
1035
1056
}
1036
1057
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
-
1050
1058
renv_json_read <- function (file = NULL , text = NULL ) {
1051
1059
1052
1060
jlerr <- NULL
1053
1061
1054
1062
# if jsonlite is loaded, use that instead
1055
1063
if (" jsonlite" %in% loadedNamespaces()) {
1056
1064
1057
- json <- catch (renv_json_read_jsonlite(file , text ))
1065
+ json <- tryCatch (renv_json_read_jsonlite(file , text ), error = identity )
1058
1066
if (! inherits(json , " error" ))
1059
1067
return (json )
1060
1068
@@ -1063,7 +1071,7 @@ local({
1063
1071
}
1064
1072
1065
1073
# 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 )
1067
1075
if (! inherits(json , " error" ))
1068
1076
return (json )
1069
1077
@@ -1076,14 +1084,14 @@ local({
1076
1084
}
1077
1085
1078
1086
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 " )
1080
1088
jsonlite :: fromJSON(txt = text , simplifyVector = FALSE )
1081
1089
}
1082
1090
1083
1091
renv_json_read_default <- function (file = NULL , text = NULL ) {
1084
1092
1085
1093
# find strings in the JSON
1086
- text <- paste(text %|| % read (file ), collapse = " \n " )
1094
+ text <- paste(text %|| % readLines (file , warn = FALSE ), collapse = " \n " )
1087
1095
pattern <- ' ["](?:(?:\\\\ .)|(?:[^"\\\\ ]))*?["]'
1088
1096
locs <- gregexpr(pattern , text , perl = TRUE )[[1 ]]
1089
1097
@@ -1131,14 +1139,14 @@ local({
1131
1139
map <- as.list(map )
1132
1140
1133
1141
# remap strings in object
1134
- remapped <- renv_json_remap (json , map )
1142
+ remapped <- renv_json_read_remap (json , map )
1135
1143
1136
1144
# evaluate
1137
1145
eval(remapped , envir = baseenv())
1138
1146
1139
1147
}
1140
1148
1141
- renv_json_remap <- function (json , map ) {
1149
+ renv_json_read_remap <- function (json , map ) {
1142
1150
1143
1151
# fix names
1144
1152
if (! is.null(names(json ))) {
@@ -1165,7 +1173,7 @@ local({
1165
1173
# recurse
1166
1174
if (is.recursive(json )) {
1167
1175
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 ))
1169
1177
}
1170
1178
}
1171
1179
@@ -1185,16 +1193,8 @@ local({
1185
1193
# construct full libpath
1186
1194
libpath <- file.path(root , prefix )
1187
1195
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 )
1198
1198
1199
1199
invisible ()
1200
1200
0 commit comments