1#' @include with_.R 2 3# lib ------------------------------------------------------------------------ 4 5set_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 16set_temp_libpath <- function(action = "prefix") { 17 paths <- tempfile("temp_libpath") 18 dir.create(paths) 19 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 40with_libpaths <- with_(set_libpaths, .libPaths) 41 42#' @rdname with_libpaths 43#' @export 44local_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 55with_temp_libpaths <- with_(set_temp_libpath, .libPaths, new = FALSE) 56 57#' @rdname with_temp_libpaths 58#' @export 59local_temp_libpaths <- local_(set_temp_libpath, .libPaths, new = FALSE) 60