R/utils.R

Defines functions fetch toss

## negative of purr::keep("name")

toss <- function(.x, .p) {
  pat <- paste(paste0("^", .p, "$"), collapse = "|")
  return(.x[!grepl(pat, names(.x))])
}

fetch <- function(path) {
  if(!curl::has_internet()) {
    message("Internet connection is down")
    return(NULL)
  }
  r <- httr::GET(path)
  if(httr::http_error(r)) {
    message("Internal error or data source has moved. Please try again.")
    return(NULL)
  } else {
    return(XML::xmlParse(httr::content(r)))
  }
}

Try the washex package in your browser

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

washex documentation built on Nov. 17, 2021, 5:18 p.m.