1
#' @include with_.R
2

3
# lib ------------------------------------------------------------------------
4

5
set_libpaths <- function(paths, action = "replace") {
6 1
  paths <- as_character(paths)
7 1
  paths <- normalizePath(paths, mustWork = TRUE)
8

9 1
  old <- .libPaths()
10 1
  paths <- merge_new(old, paths, action)
11

12 1
  .libPaths(paths)
13 1
  invisible(old)
14
}
15

16
set_temp_libpath <- function(action = "prefix") {
17 1
  paths <- tempfile("temp_libpath")
18 1
  dir.create(paths)
19 1
  set_libpaths(paths, action = action)
20
}
21

22
#' Library paths
23
#'
24
#' Temporarily change library paths.
25
#'
26
#' @template with
27
#' @param new `[character]`\cr New library paths
28
#' @param action `[character(1)]`\cr should new values `"replace"`, `"prefix"` or
29
#'   `"suffix"` existing paths.
30
#' @inheritParams with_collate
31
#' @seealso [.libPaths()]
32
#' @family libpaths
33
#' @examples
34
#' .libPaths()
35
#' new_lib <- tempfile()
36
#' dir.create(new_lib)
37
#' with_libpaths(new_lib, print(.libPaths()))
38
#' unlink(new_lib, recursive = TRUE)
39
#' @export
40
with_libpaths <- with_(set_libpaths, .libPaths)
41

42
#' @rdname with_libpaths
43
#' @export
44
local_libpaths <- local_(set_libpaths, .libPaths)
45

46
#' Library paths
47
#'
48
#' Temporarily prepend a new temporary directory to the library paths.
49
#'
50
#' @template with
51
#' @seealso [.libPaths()]
52
#' @inheritParams with_libpaths
53
#' @family libpaths
54
#' @export
55
with_temp_libpaths <- with_(set_temp_libpath, .libPaths, new = FALSE)
56

57
#' @rdname with_temp_libpaths
58
#' @export
59
local_temp_libpaths <- local_(set_temp_libpath, .libPaths, new = FALSE)

Read our documentation on viewing source code .

Loading