22local({
33
44 # the requested version of renv
5- version <- " 1.1.5"
5+ version <- " 1.2.0"
6+ attr(version , " md5" ) <- " b7d230b07507f361d3bcf794d157a188"
67 attr(version , " sha" ) <- NULL
78
89 # the project directory
@@ -168,6 +169,16 @@ local({
168169 if (quiet )
169170 return (invisible ())
170171
172+ # also check for config environment variables that should suppress messages
173+ # https://github.com/rstudio/renv/issues/2214
174+ enabled <- Sys.getenv(" RENV_CONFIG_STARTUP_QUIET" , unset = NA )
175+ if (! is.na(enabled ) && tolower(enabled ) %in% c(" true" , " 1" ))
176+ return (invisible ())
177+
178+ enabled <- Sys.getenv(" RENV_CONFIG_SYNCHRONIZED_CHECK" , unset = NA )
179+ if (! is.na(enabled ) && tolower(enabled ) %in% c(" false" , " 0" ))
180+ return (invisible ())
181+
171182 msg <- sprintf(fmt , ... )
172183 cat(msg , file = stdout(), sep = if (appendLF ) " \n " else " " )
173184
@@ -215,6 +226,20 @@ local({
215226 section <- header(sprintf(" Bootstrapping renv %s" , friendly ))
216227 catf(section )
217228
229+ # ensure the target library path exists; required for file.copy(..., recursive = TRUE)
230+ dir.create(library , showWarnings = FALSE , recursive = TRUE )
231+
232+ # try to install renv from cache
233+ md5 <- attr(version , " md5" , exact = TRUE )
234+ if (length(md5 )) {
235+ pkgpath <- renv_bootstrap_find(version )
236+ if (length(pkgpath ) && file.exists(pkgpath )) {
237+ ok <- file.copy(pkgpath , library , recursive = TRUE )
238+ if (isTRUE(ok ))
239+ return (invisible ())
240+ }
241+ }
242+
218243 # attempt to download renv
219244 catf(" - Downloading renv ... " , appendLF = FALSE )
220245 withCallingHandlers(
@@ -240,7 +265,6 @@ local({
240265
241266 # add empty line to break up bootstrapping from normal output
242267 catf(" " )
243-
244268 return (invisible ())
245269 }
246270
@@ -257,12 +281,20 @@ local({
257281 repos <- Sys.getenv(" RENV_CONFIG_REPOS_OVERRIDE" , unset = NA )
258282 if (! is.na(repos )) {
259283
260- # check for RSPM; if set, use a fallback repository for renv
261- rspm <- Sys.getenv(" RSPM" , unset = NA )
262- if (identical(rspm , repos ))
263- repos <- c(RSPM = rspm , CRAN = cran )
284+ # split on ';' if present
285+ parts <- strsplit(repos , " ;" , fixed = TRUE )[[1L ]]
264286
265- return (repos )
287+ # split into named repositories if present
288+ idx <- regexpr(" =" , parts , fixed = TRUE )
289+ keys <- substring(parts , 1L , idx - 1L )
290+ vals <- substring(parts , idx + 1L )
291+ names(vals ) <- keys
292+
293+ # if we have a single unnamed repository, call it CRAN
294+ if (length(vals ) == 1L && identical(keys , " " ))
295+ names(vals ) <- " CRAN"
296+
297+ return (vals )
266298
267299 }
268300
@@ -511,6 +543,51 @@ local({
511543
512544 }
513545
546+ renv_bootstrap_find <- function (version ) {
547+
548+ path <- renv_bootstrap_find_cache(version )
549+ if (length(path ) && file.exists(path )) {
550+ catf(" - Using renv %s from global package cache" , version )
551+ return (path )
552+ }
553+
554+ }
555+
556+ renv_bootstrap_find_cache <- function (version ) {
557+
558+ md5 <- attr(version , " md5" , exact = TRUE )
559+ if (is.null(md5 ))
560+ return ()
561+
562+ # infer path to renv cache
563+ cache <- Sys.getenv(" RENV_PATHS_CACHE" , unset = " " )
564+ if (! nzchar(cache )) {
565+ root <- Sys.getenv(" RENV_PATHS_ROOT" , unset = NA )
566+ if (! is.na(root ))
567+ cache <- file.path(root , " cache" )
568+ }
569+
570+ if (! nzchar(cache )) {
571+ tools <- asNamespace(" tools" )
572+ if (is.function(tools $ R_user_dir )) {
573+ root <- tools $ R_user_dir(" renv" , " cache" )
574+ cache <- file.path(root , " cache" )
575+ }
576+ }
577+
578+ # start completing path to cache
579+ file.path(
580+ cache ,
581+ renv_bootstrap_cache_version(),
582+ renv_bootstrap_platform_prefix(),
583+ " renv" ,
584+ version ,
585+ md5 ,
586+ " renv"
587+ )
588+
589+ }
590+
514591 renv_bootstrap_download_tarball <- function (version ) {
515592
516593 # if the user has provided the path to a tarball via
@@ -979,7 +1056,7 @@ local({
9791056
9801057 renv_bootstrap_validate_version_release <- function (version , description ) {
9811058 expected <- description [[" Version" ]]
982- is.character(expected ) && identical(expected , version )
1059+ is.character(expected ) && identical(c( expected ), c( version ) )
9831060 }
9841061
9851062 renv_bootstrap_hash_text <- function (text ) {
@@ -1158,6 +1235,21 @@ local({
11581235 }
11591236
11601237 renv_bootstrap_run <- function (project , libpath , version ) {
1238+ tryCatch(
1239+ renv_bootstrap_run_impl(project , libpath , version ),
1240+ error = function (e ) {
1241+ msg <- paste(
1242+ " failed to bootstrap renv: the project will not be loaded." ,
1243+ paste(" Reason:" , conditionMessage(e )),
1244+ " Use `renv::activate()` to re-initialize the project." ,
1245+ sep = " \n "
1246+ )
1247+ warning(msg , call. = FALSE )
1248+ }
1249+ )
1250+ }
1251+
1252+ renv_bootstrap_run_impl <- function (project , libpath , version ) {
11611253
11621254 # perform bootstrap
11631255 bootstrap(version , libpath )
@@ -1181,6 +1273,18 @@ local({
11811273
11821274 }
11831275
1276+ renv_bootstrap_cache_version <- function () {
1277+ # NOTE: users should normally not override the cache version;
1278+ # this is provided just to make testing easier
1279+ Sys.getenv(" RENV_CACHE_VERSION" , unset = " v5" )
1280+ }
1281+
1282+ renv_bootstrap_cache_version_previous <- function () {
1283+ version <- renv_bootstrap_cache_version()
1284+ number <- as.integer(substring(version , 2L ))
1285+ paste(" v" , number - 1L , sep = " " )
1286+ }
1287+
11841288 renv_json_read <- function (file = NULL , text = NULL ) {
11851289
11861290 jlerr <- NULL
0 commit comments