| 1 |
|
| 2 |
#' Isolate a project |
| 3 |
#' |
| 4 |
#' Copy packages from the renv cache directly into the project library, so |
| 5 |
#' that the project can continue to function independently of the renv cache. |
| 6 |
#' |
| 7 |
#' After calling `isolate()`, renv will still be able to use the cache on |
| 8 |
#' future [install()]s and [restore()]s. If you'd prefer that renv copy |
| 9 |
#' packages from the cache, rather than use symlinks, you can set the renv |
| 10 |
#' configuration option: |
| 11 |
#' |
| 12 |
#' ``` |
| 13 |
#' options(renv.config.cache.symlinks = FALSE) |
| 14 |
#' ``` |
| 15 |
#' |
| 16 |
#' to force renv to copy packages from the cache, as opposed to symlinking |
| 17 |
#' them. If you'd like to disable the cache altogether for a project, you can |
| 18 |
#' use: |
| 19 |
#' |
| 20 |
#' ``` |
| 21 |
#' settings$use.cache(FALSE) |
| 22 |
#' ``` |
| 23 |
#' |
| 24 |
#' to explicitly disable the cache for the project. |
| 25 |
#' |
| 26 |
#' @inherit renv-params |
| 27 |
#' |
| 28 |
#' @export |
| 29 |
#' |
| 30 |
#' @examples |
| 31 |
#' \dontrun{ |
| 32 |
#' |
| 33 |
#' # isolate a project |
| 34 |
#' renv::isolate() |
| 35 |
#' |
| 36 |
#' } |
| 37 |
isolate <- function(project = NULL) { |
| 38 |
|
| 39 |
project <- renv_project_resolve(project) |
| 40 |
renv_project_lock(project = project) |
| 41 |
|
| 42 |
if (renv_platform_windows()) |
| 43 |
renv_isolate_windows(project) |
| 44 |
else |
| 45 |
renv_isolate_unix(project) |
| 46 |
|
| 47 |
invisible(project) |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
renv_isolate_unix <- function(project) { |
| 52 |
|
| 53 |
library <- renv_paths_library(project = project) |
| 54 |
targets <- list.files(library, full.names = TRUE) |
| 55 |
|
| 56 |
sources <- Sys.readlink(targets) |
| 57 |
islink <- !is.na(sources) & nzchar(sources) |
| 58 |
|
| 59 |
sources <- sources[islink] |
| 60 |
targets <- targets[islink] |
| 61 |
names(targets) <- sources |
| 62 |
|
| 63 |
if (length(targets)) { |
| 64 |
printf("- Copying packages into the private library ... ") |
| 65 |
unlink(targets) |
| 66 |
copy <- renv_progress_callback(renv_file_copy, length(targets)) |
| 67 |
enumerate(targets, copy, overwrite = TRUE) |
| 68 |
writef("Done!") |
| 69 |
} |
| 70 |
|
| 71 |
writef("- This project has been isolated from the cache.") |
| 72 |
invisible(project) |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
renv_isolate_windows <- function(project) { |
| 77 |
|
| 78 |
library <- renv_paths_library(project = project) |
| 79 |
targets <- list.files(library, full.names = TRUE) |
| 80 |
|
| 81 |
sources <- map_chr(targets, renv_cache_path) |
| 82 |
names(targets) <- sources |
| 83 |
|
| 84 |
if (length(targets)) { |
| 85 |
printf("- Copying packages into the private library ... ") |
| 86 |
targets <- targets[file.exists(sources)] |
| 87 |
unlink(targets) |
| 88 |
copy <- renv_progress_callback(renv_file_copy, length(targets)) |
| 89 |
enumerate(targets, copy, overwrite = TRUE) |
| 90 |
writef("Done!") |
| 91 |
} |
| 92 |
|
| 93 |
writef("- This project has been isolated from the cache.") |
| 94 |
invisible(project) |
| 95 |
|
| 96 |
} |