File: utils.R

package info (click to toggle)
r-cran-tinytest 1.4.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,072 kB
  • sloc: sh: 14; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 1,041 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

# standard convenience functions
catf  <- function(fmt,...) cat(sprintf(fmt,...))
stopf <- function(fmt,...) stop(sprintf(fmt,...), call.=FALSE)
warnf <- function(fmt,...) warning(sprintf(fmt,...), call.=FALSE)
msgf  <- function(fmt, ...) message(sprintf(fmt,...))

# support R versions < 3.2, that lack trimws() and dir.exists()

if (getRversion() < "3.2.0"){
  trimws <- function (x, which = c("both", "left", "right"), whitespace = "[ \t\r\n]") {
    which <- match.arg(which)
    mysub <- function(re, x) sub(re, "", x, perl = TRUE)
    switch(which,
           left = mysub(paste0("^", whitespace, "+"), x),
           right = mysub(paste0(whitespace, "+$"), x),
           both = mysub(paste0(whitespace, "+$"), mysub(paste0("^", whitespace, "+"), x)))
  }

  dir.exists <- function (paths) {
    x = base::file.info(paths)$isdir
    !is.na(x) & x
  }
}
# support for R versions < 3.6 that lack nullfile()
if (getRversion() < "3.6.0"){
  nullfile <- function () {
    if (.Platform$OS.type == "windows") "nul:" else "/dev/null"
  }
}