R/utils.R

Defines functions stop_if_not is_nullfile nullfile

nullfile <- function() {
  switch(.Platform$OS.type,
    windows = "NUL",
    "/dev/null" #nolint
  )
}

is_nullfile <- function(file) {
  file <- normalizePath(file, mustWork = FALSE)
  file <- tolower(file)

  if (.Platform$OS.type == "windows") {
    # Any filename of NUL, NUL.<any extension>, NUL:<any path>
    file <- gsub("[.:].*", "", basename(file))
    (file == "nul")
  } else {
    (file == "/dev/null") #nolint
  }
}

stop_if_not <- function(...) {
  res <- list(...)
  n <- length(res)
  if (n == 0L) return()

  for (ii in 1L:n) {
    res_ii <- .subset2(res, ii)
    if (length(res_ii) != 1L || is.na(res_ii) || !res_ii) {
        mc <- match.call()
        call <- deparse(mc[[ii + 1]], width.cutoff = 60L)
        if (length(call) > 1L) call <- paste(call[1L], "...")
        stop(sQuote(call), " is not TRUE", call. = FALSE, domain = NA)
    }
  }
}

Try the R.devices package in your browser

Any scripts or data that you put into this service are public.

R.devices documentation built on Oct. 30, 2019, 10:58 a.m.