1# nocov start - compat-oldrel (last updated: rlang 0.1.2)
2
3# This file serves as a reference for compatibility functions for old
4# versions of R. Please find the most recent version in rlang's
5# repository.
6
7
8# R 3.2.0 ------------------------------------------------------------
9
10if (getRversion() < "3.2.0") {
11
12  dir_exists <- function(path) {
13    !identical(path, "") && file.exists(paste0(path, .Platform$file.sep))
14  }
15  dir.exists <- function(paths) {
16    vapply(paths, dir_exists, logical(1))
17  }
18
19  names <- function(x) {
20    if (is.environment(x)) {
21      return(ls(x, all.names = TRUE))
22    } else {
23      return(base::names(x))
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    )
37  }
38
39}
40
41# nocov end
42