22local({
33
44 # the requested version of renv
5- version <- " 1.1.5"
5+ version <- " 1.1.6"
6+ attr(version , " md5" ) <- " 3036c4b273d882c56e8cdd660ebaf6f0"
67 attr(version , " sha" ) <- NULL
78
89 # the project directory
@@ -215,6 +216,16 @@ local({
215216 section <- header(sprintf(" Bootstrapping renv %s" , friendly ))
216217 catf(section )
217218
219+ # try to install renv from cache
220+ md5 <- attr(version , " md5" , exact = TRUE )
221+ if (length(md5 )) {
222+ pkgpath <- renv_bootstrap_find(version )
223+ if (length(pkgpath ) && file.exists(pkgpath )) {
224+ file.copy(pkgpath , library , recursive = TRUE )
225+ return (invisible ())
226+ }
227+ }
228+
218229 # attempt to download renv
219230 catf(" - Downloading renv ... " , appendLF = FALSE )
220231 withCallingHandlers(
@@ -240,7 +251,6 @@ local({
240251
241252 # add empty line to break up bootstrapping from normal output
242253 catf(" " )
243-
244254 return (invisible ())
245255 }
246256
@@ -256,14 +266,22 @@ local({
256266 # check for repos override
257267 repos <- Sys.getenv(" RENV_CONFIG_REPOS_OVERRIDE" , unset = NA )
258268 if (! is.na(repos )) {
259-
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 )
264-
265- return (repos )
266-
269+
270+ # split on ';' if present
271+ parts <- strsplit(repos , " ;" , fixed = TRUE )[[1L ]]
272+
273+ # split into named repositories if present
274+ idx <- regexpr(" =" , parts , fixed = TRUE )
275+ keys <- substring(parts , 1L , idx - 1L )
276+ vals <- substring(parts , idx + 1L )
277+ names(vals ) <- keys
278+
279+ # if we have a single unnamed repository, call it CRAN
280+ if (length(vals ) == 1L && identical(keys , " " ))
281+ names(vals ) <- " CRAN"
282+
283+ return (vals )
284+
267285 }
268286
269287 # check for lockfile repositories
@@ -511,6 +529,45 @@ local({
511529
512530 }
513531
532+ renv_bootstrap_find <- function (version ) {
533+
534+ path <- renv_bootstrap_find_cache(version )
535+ if (length(path ) && file.exists(path )) {
536+ catf(" - Using renv %s from global package cache" , version )
537+ return (path )
538+ }
539+
540+ }
541+
542+ renv_bootstrap_find_cache <- function (version ) {
543+
544+ md5 <- attr(version , " md5" , exact = TRUE )
545+ if (is.null(md5 ))
546+ return ()
547+
548+ # infer path to renv cache
549+ cache <- Sys.getenv(" RENV_PATHS_CACHE" , unset = " " )
550+ if (! nzchar(cache )) {
551+ tools <- asNamespace(" tools" )
552+ if (is.function(tools $ R_user_dir )) {
553+ root <- tools $ R_user_dir(" renv" , " cache" )
554+ cache <- file.path(root , " cache" )
555+ }
556+ }
557+
558+ # start completing path to cache
559+ file.path(
560+ cache ,
561+ renv_bootstrap_cache_version(),
562+ renv_bootstrap_platform_prefix(),
563+ " renv" ,
564+ version ,
565+ md5 ,
566+ " renv"
567+ )
568+
569+ }
570+
514571 renv_bootstrap_download_tarball <- function (version ) {
515572
516573 # if the user has provided the path to a tarball via
@@ -1181,6 +1238,18 @@ local({
11811238
11821239 }
11831240
1241+ renv_bootstrap_cache_version <- function () {
1242+ # NOTE: users should normally not override the cache version;
1243+ # this is provided just to make testing easier
1244+ Sys.getenv(" RENV_CACHE_VERSION" , unset = " v5" )
1245+ }
1246+
1247+ renv_bootstrap_cache_version_previous <- function () {
1248+ version <- renv_bootstrap_cache_version()
1249+ number <- as.integer(substring(version , 2L ))
1250+ paste(" v" , number - 1L , sep = " " )
1251+ }
1252+
11841253 renv_json_read <- function (file = NULL , text = NULL ) {
11851254
11861255 jlerr <- NULL
0 commit comments