|
1 | | -# nocov start - compat-oldrel (last updated: rlang 0.1.9000) |
| 1 | +# nocov start - compat-oldrel (last updated: rlang 0.1.2) |
2 | 2 |
|
3 | 3 | # This file serves as a reference for compatibility functions for old |
4 | | -# versions of R. |
5 | | - |
6 | | - |
7 | | -# Compat function for capture functions (that will hopefully make |
8 | | -# their way to the next R version) ----------------------------------- |
9 | | - |
10 | | -if (TRUE || utils::packageVersion("base") < "3.4.0") { |
11 | | - |
12 | | - captureArg <- function(x, strict = TRUE) { |
13 | | - caller_env <- parent.frame() |
14 | | - |
15 | | - if (identical(caller_env, globalenv())) { |
16 | | - stop("must be called in a function") |
17 | | - } |
18 | | - if (missing(x)) { |
19 | | - stop("argument \"x\" is missing") |
20 | | - } |
21 | | - |
22 | | - .Call(rlang_capturearg, NULL, NULL, pairlist(caller_env, strict), get_env()) |
23 | | - } |
24 | | - |
25 | | - captureDots <- function(strict = TRUE) { |
26 | | - caller_env <- parent.frame() |
27 | | - |
28 | | - if (!exists("...", caller_env)) { |
29 | | - stop("must be called in a function where dots exist") |
30 | | - } |
31 | | - |
32 | | - .Call(rlang_capturedots, NULL, NULL, pairlist(caller_env, strict), get_env()) |
33 | | - } |
34 | | - |
35 | | -} |
| 4 | +# versions of R. Please find the most recent version in rlang's |
| 5 | +# repository. |
36 | 6 |
|
37 | 7 |
|
38 | 8 | # R 3.2.0 ------------------------------------------------------------ |
39 | 9 |
|
40 | | -if (utils::packageVersion("base") < "3.2.0") { |
| 10 | +if (getRversion() < "3.2.0") { |
41 | 11 |
|
42 | 12 | dir_exists <- function(path) { |
43 | 13 | !identical(path, "") && file.exists(paste0(path, .Platform$file.sep)) |
44 | 14 | } |
45 | 15 | dir.exists <- function(paths) { |
46 | | - map_lgl(paths, dir_exists) |
| 16 | + vapply(paths, dir_exists, logical(1)) |
47 | 17 | } |
48 | 18 |
|
49 | 19 | names <- function(x) { |
50 | 20 | if (is.environment(x)) { |
51 | | - ls(x, all.names = TRUE) |
| 21 | + return(ls(x, all.names = TRUE)) |
52 | 22 | } else { |
53 | | - base::names(x) |
| 23 | + return(base::names(x)) |
54 | 24 | } |
| 25 | + |
| 26 | + # So R CMD check on old versions of R sees a generic, since we |
| 27 | + # declare a names() method for dictionary objects |
| 28 | + UseMethod("names") |
| 29 | + } |
| 30 | + |
| 31 | + trimws <- function(x, which = c("both", "left", "right")) { |
| 32 | + switch(match.arg(which), |
| 33 | + left = sub("^[ \t\r\n]+", "", x, perl = TRUE), |
| 34 | + right = sub("[ \t\r\n]+$", "", x, perl = TRUE), |
| 35 | + both = trimws(trimws(x, "left"), "right") |
| 36 | + ) |
55 | 37 | } |
56 | 38 |
|
57 | 39 | } |
|
0 commit comments