| 1 |
make_call <- function(...) { |
| 2 |
as.call(list(...)) |
| 3 |
} |
| 4 |
|
| 5 |
vlapply <- function(X, FUN, ..., FUN.VALUE = logical(1)) { |
| 6 |
vapply(X, FUN, ..., FUN.VALUE = FUN.VALUE) |
| 7 |
} |
| 8 |
|
| 9 |
names2 <- function(x) { |
| 10 |
nms <- names(x) |
| 11 |
if (is.null(nms)) { |
| 12 |
rep("", length(x)) |
| 13 |
} else { |
| 14 |
nms[is.na(nms)] <- "" |
| 15 |
nms |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
#' Shim for tools::makevars_user() |
| 20 |
#' @keywords internal |
| 21 |
#' @export |
| 22 |
makevars_user <- function() { |
| 23 |
if (getRversion() >= "3.3") { |
| 24 |
return(tools::makevars_user()) |
| 25 |
} |
| 26 |
# Below is tools::makevars_user() from R 3.6.2 |
| 27 |
m <- character() |
| 28 |
if (.Platform$OS.type == "windows") { |
| 29 |
if (!is.na(f <- Sys.getenv("R_MAKEVARS_USER", NA_character_))) { |
| 30 |
if (file.exists(f)) { |
| 31 |
m <- f |
| 32 |
} |
| 33 |
} else if ( |
| 34 |
(Sys.getenv("R_ARCH") == "/x64") && |
| 35 |
file.exists(f <- path.expand("~/.R/Makevars.win64")) |
| 36 |
) { |
| 37 |
m <- f |
| 38 |
} else if (file.exists(f <- path.expand("~/.R/Makevars.win"))) { |
| 39 |
m <- f |
| 40 |
} else if (file.exists(f <- path.expand("~/.R/Makevars"))) { |
| 41 |
m <- f |
| 42 |
} |
| 43 |
} else { |
| 44 |
if (!is.na(f <- Sys.getenv("R_MAKEVARS_USER", NA_character_))) { |
| 45 |
if (file.exists(f)) { |
| 46 |
m <- f |
| 47 |
} |
| 48 |
} else if ( |
| 49 |
file.exists( |
| 50 |
f <- path.expand(paste0("~/.R/Makevars-", Sys.getenv("R_PLATFORM"))) |
| 51 |
) |
| 52 |
) { |
| 53 |
m <- f |
| 54 |
} else if (file.exists(f <- path.expand("~/.R/Makevars"))) { |
| 55 |
m <- f |
| 56 |
} |
| 57 |
} |
| 58 |
m |
| 59 |
} |
| 60 |
|
| 61 |
as_character <- function(x) { |
| 62 |
nms <- names(x) |
| 63 |
res <- as.character(x) |
| 64 |
names(res) <- nms |
| 65 |
res |
| 66 |
} |
| 67 |
|
| 68 |
list_combine <- function(rhs, lhs) { |
| 69 |
for (nme in names(lhs)) { |
| 70 |
rhs[nme] <- lhs[nme] |
| 71 |
} |
| 72 |
rhs |
| 73 |
} |
| 74 |
|
| 75 |
# Helper to implement `options()`-like splicing |
| 76 |
auto_splice <- function(x) { |
| 77 |
if (length(x) == 1 && is.null(names(x)) && is.list(x[[1]])) { |
| 78 |
x[[1]] |
| 79 |
} else { |
| 80 |
x |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
setNames <- function(x = nm, nm) { |
| 85 |
names(x) <- nm |
| 86 |
x |
| 87 |
} |
| 88 |
|
| 89 |
# base implementation of rlang::is_interactive() |
| 90 |
is_interactive <- function() { |
| 91 |
opt <- getOption("rlang_interactive") |
| 92 |
if (!is.null(opt)) { |
| 93 |
return(opt) |
| 94 |
} |
| 95 |
if (knitr_in_progress()) { |
| 96 |
return(FALSE) |
| 97 |
} |
| 98 |
if (identical(Sys.getenv("TESTTHAT"), "true")) { |
| 99 |
return(FALSE) |
| 100 |
} |
| 101 |
interactive() |
| 102 |
} |
| 103 |
|
| 104 |
`%||%` <- function(x, y) { |
| 105 |
if (is.null(x)) y else x |
| 106 |
} |