R/provider.R

Defines functions prevedere_providers

Documented in prevedere_providers

#' Providers
#'
#' Retrieve a list of entities whose data is available in Prevedere
#'
#' @inheritParams prevedere_indicator_series
#'
#' @return A dataframe (or list if \code{raw = TRUE}) of provider metadata.
#' @export
#'
#' @examples
#' \dontrun{
#' k <- "1235467abcdefg"
#'
#' prevedere_providers(key = k)
#' }
prevedere_providers <- function(key, raw = FALSE) {
  path <- "provider"
  p <- prevedere_fetch(key, path)

  if (raw) {
    return(p)
  }

  # store names of list elements
  p.names <- names(p[[1]])

  # recursively fill NULL values in the list so that the columns still appear
  # in the new dataframe
  p <- lapply(p, function(x) lapply(x, function(y) ifelse(is.null(y), "", y)))

  # convert nested list into a dataframe
  p <- data.frame(matrix(unlist(p),
    nrow = length(p),
    byrow = T
  ),
  stringsAsFactors = FALSE
  )

  # give dataframe columns the same names as the original list elements
  colnames(p) <- p.names

  p
}

Try the prevederer package in your browser

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

prevederer documentation built on July 23, 2019, 5:05 p.m.