R/get_iso3.R

Defines functions get_iso3_codes

Documented in get_iso3_codes

#' get_iso3_codes
#'
#' Non memoised version: Retrieve list of country names and iso3 codes
#' accepted by DDH
#' @param root_url character: API root URL
#'
#' @return dataframe
#'

get_iso3_codes <- function(root_url = dkanr::get_url()) {
  # Build url
  path <- "api/taxonomy/listvalues"
  url <- httr::modify_url(root_url, path = path)
  # Send request
  out <- jsonlite::fromJSON(url)
  # keep only country names LOVs
  out <- out[out[["vocabulary_name"]] == "geographical_coverage",
             c("list_value_name", "field_wbddh_country_iso3")]
  names(out) <- c("country_name", "iso3")

  return(out)
}

#' get_iso3
#'
#' Retrieve list of country names and iso3 codes accepted by DDH
#'
#' @param root_url character: API root URL
#'
#' @return dataframe
#' @export
#'
get_iso3 <- memoise::memoise(get_iso3_codes)
tonyfujs/ddhconnect documentation built on June 3, 2020, 10:33 a.m.