R/utils.R

Defines functions bail bail_if bail_if_not url_path rawToChar

bail <- function(...){
  stop(sprintf(...), call. = FALSE)
}

bail_if <- function(x, ...){
  if(isTRUE(as.logical(x)))
    bail(...)
}

bail_if_not <- function(x, ...){
  if(!isTRUE(as.logical(x)))
    bail(...)
}

url_path <- function(...){
  args <- c(...)
  args <- sub("^/", "", args)
  args <- sub("/$", "", args)
  do.call(file.path, c(as.list(args), fsep = "/"))
}

# Make rawToChar consistent on Unix and Windows
rawToChar <- function(x){
  out <- base::rawToChar(x)
  Encoding(out) <- 'UTF-8'
  out
}
opencpu/client documentation built on May 24, 2019, 6:13 a.m.