1 2# standard convenience functions 3catf <- function(fmt,...) cat(sprintf(fmt,...)) 4stopf <- function(fmt,...) stop(sprintf(fmt,...), call.=FALSE) 5warnf <- function(fmt,...) warning(sprintf(fmt,...), call.=FALSE) 6msgf <- function(fmt, ...) message(sprintf(fmt,...)) 7 8# support R versions < 3.2, that lack trimws() and dir.exists() 9 10if (getRversion() < "3.2.0"){ 11 trimws <- function (x, which = c("both", "left", "right"), whitespace = "[ \t\r\n]") { 12 which <- match.arg(which) 13 mysub <- function(re, x) sub(re, "", x, perl = TRUE) 14 switch(which, 15 left = mysub(paste0("^", whitespace, "+"), x), 16 right = mysub(paste0(whitespace, "+$"), x), 17 both = mysub(paste0(whitespace, "+$"), mysub(paste0("^", whitespace, "+"), x))) 18 } 19 20 dir.exists <- function (paths) { 21 x = base::file.info(paths)$isdir 22 !is.na(x) & x 23 } 24} 25# support for R versions < 3.6 that lack nullfile() 26if (getRversion() < "3.6.0"){ 27 nullfile <- function () { 28 if (.Platform$OS.type == "windows") "nul:" else "/dev/null" 29 } 30} 31