tests/testthat/helper-webmockr.R

sm <- function(x) suppressMessages(x)

get_err_mssg <- function(x) {
  tmp <- tryCatch(x, error = function(e) e)
  if (inherits(tmp, "error")) unclass(tmp)$message else tmp
}

# from https://stackoverflow.com/a/14838321/1091766
re_escape <- function(strings){
  vals <- c("\\\\", "\\[", "\\]", "\\(", "\\)",
            "\\{", "\\}", "\\^", "\\$","\\*",
            "\\+", "\\?", "\\.", "\\|")
  replace.vals <- paste0("\\\\", vals)
  for(i in seq_along(vals)){
    strings <- gsub(vals[i], replace.vals[i], strings)
  }
  strings
}

base_url = "http://hb.opencpu.org"
hb <- function(x = NULL) if (is.null(x)) base_url else paste0(base_url, x)
ropenscilabs/webmockr documentation built on July 30, 2024, 10:37 a.m.