Debian Codegraph @

R/libpaths.R

raw
1 #' @include with_.R
2
3 # lib ------------------------------------------------------------------------
4
5 set_libpaths <- function(paths, action = "replace") {
6 paths <- as_character(paths)
7 paths <- normalizePath(paths, mustWork = TRUE)
8
9 old <- .libPaths()
10 paths <- merge_new(old, paths, action)
11
12 .libPaths(paths)
13 invisible(old)
14 }
15
16 get_libpaths <- function(...) {
17 .libPaths()
18 }
19
20 set_temp_libpath <- function(action = "prefix") {
21 paths <- tempfile("temp_libpath")
22 dir.create(paths)
23 set_libpaths(paths, action = action)
24 }
25
26 #' Library paths
27 #'
28 #' Temporarily change library paths.
29 #'
30 #' @template with
31 #' @param new `[character]`\cr New library paths
32 #' @param action `[character(1)]`\cr should new values `"replace"`, `"prefix"` or
33 #' `"suffix"` existing paths.
34 #' @inheritParams with_collate
35 #' @seealso [.libPaths()]
36 #' @family libpaths
37 #' @examples
38 #' .libPaths()
39 #' new_lib <- tempfile()
40 #' dir.create(new_lib)
41 #' with_libpaths(new_lib, print(.libPaths()))
42 #' unlink(new_lib, recursive = TRUE)
43 #' @export
44 with_libpaths <- with_(set_libpaths, .libPaths, get = get_libpaths)
45
46 #' @rdname with_libpaths
47 #' @export
48 local_libpaths <- local_(set_libpaths, .libPaths, get = get_libpaths)
49
50 #' Library paths
51 #'
52 #' Temporarily prepend a new temporary directory to the library paths.
53 #'
54 #' @template with
55 #' @seealso [.libPaths()]
56 #' @inheritParams with_libpaths
57 #' @family libpaths
58 #' @export
59 with_temp_libpaths <- with_(
60 set_temp_libpath,
61 .libPaths,
62 get = get_libpaths,
63 new = FALSE
64 )
65
66 #' @rdname with_temp_libpaths
67 #' @export
68 local_temp_libpaths <- local_(
69 set_temp_libpath,
70 .libPaths,
71 get = get_libpaths,
72 new = FALSE
73 )