R/parse_qwi_message.R

Defines functions parse_qwi_message

Documented in parse_qwi_message

#'@title parse_qwi
#'@description An internally used function to parse the returned API call.
#'@param x a returned call response from the US Census QWI API
#'@export

parse_qwi_message <- function(x) {
  if (class(x) != "response") {
    stop("You have not passed a valid response")
  }
  y <- dplyr::as_data_frame(
    jsonlite::fromJSON(
      httr::content(x, as = "text", encoding = "UTF-8")
      )
    )
  y <- stats::setNames(y, y[1, ])
  y <- y[-1, ]
  y <- tidyr::gather(y, "parameter", "value",-c(2:ncol(y)))
}

Try the tidyqwi package in your browser

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

tidyqwi documentation built on May 4, 2020, 5:10 p.m.