R/utils.R

Defines functions merge_multis date_convert guardian_query

#'@importFrom httr stop_for_status GET content user_agent
guardian_query <- function(path, ...){
  url <- paste0("https://content.guardianapis.com/", path)
  result <- httr::GET(url)
  httr::stop_for_status(result)
  content <- httr::content(result)
  if(length(content$response$results) == 0){
    stop("No results found")
  }
  return(content)
}

date_convert <- function(date){
  
  if(any(c("POSIXlt", "POSIXct") %in% class(date))){
    date <- as.Date(date)
  }
  return(as.character(date))
}

# Merges multiple args
merge_multis <- function(args){
  return(paste0(args, collapse = ","))
}

Try the rdian package in your browser

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

rdian documentation built on May 30, 2017, 6:39 a.m.