1
# path -----------------------------------------------------------------------
2

3
get_path <- function() {
4 1
  strsplit(Sys.getenv("PATH"), .Platform$path.sep)[[1]]
5
}
6

7
set_path <- function(path, action = "prefix") {
8 1
  path <- as_character(path)
9 1
  path <- normalizePath(path, mustWork = FALSE)
10

11 1
  old <- get_path()
12 1
  path <- merge_new(old, path, action)
13

14 1
  path <- paste(path, collapse = .Platform$path.sep)
15 1
  Sys.setenv(PATH = path)
16 1
  invisible(old)
17
}
18

19
#' PATH environment variable
20
#'
21
#' Temporarily change the system search path.
22
#'
23
#' @template with
24
#' @param new `[character]`\cr New `PATH` entries
25
#' @param action `[character(1)]`\cr Should new values `"replace"`, `"prefix"` or
26
#'   `"suffix"` existing paths
27
#' @inheritParams with_collate
28
#' @seealso [Sys.setenv()]
29
#' @examples
30
#' # temporarily modify the system PATH, *replacing* the current path
31
#' with_path(getwd(), Sys.getenv("PATH"))
32

33
#' # temporarily modify the system PATH, *appending* to the current path
34
#' with_path(getwd(), Sys.getenv("PATH"), "suffix")
35
#' @export
36
with_path <- with_(set_path, function(old) set_path(old, "replace"))
37

38
#' @rdname with_path
39
#' @export
40
local_path <- local_(set_path, function(old) set_path(old, "replace"))

Read our documentation on viewing source code .

Loading