nassqs_GET: Issue a GET request to the NASS 'Quick Stats' API

View source: R/request.R

nassqs_GETR Documentation

Issue a GET request to the NASS 'Quick Stats' API


This is the workhorse of the package that provides the core request functionality to the NASS 'Quick Stats' API: In most cases nassqs() or other high-level functions should be used. nassqs_GET() uses httr::GET() to make a HTTP GET request, which returns a request object which must then be parsed to a data.frame, list, or other R object. Higher-level functions will do that parsing automatically. However, if you need access to the request object directly, nassqs_GET() provides that.


  api_path = c("api_GET", "get_param_values", "get_counts"),
  progress_bar = TRUE,
  format = c("csv", "json", "xml")



either a named list of parameters or a series of parameters to use in the query


the API path that determines the type of request being made.


whether to display the project bar or not.


The format to return the query in. Only useful if as = "text".


a httr::GET() response object


## Not run: 
  # Yields for corn in 2012 in Washington
  params <- list(commodity_desc = "CORN",
                 year = 2012,
                 agg_level_desc = "STATE",
                 state_alpha = "WA",
                 statisticcat_desc = "YIELD")

  # Returns a request object that must be parsed either manually or
  # by using nassqs_parse()
  response <- nassqs_GET(params)
  yields <- nassqs_parse(response)

  # Get the number of records that would be returned for a given request
  # Equivalent to 'nassqs_record_count(params)'
  response <- nassqs_GET(params, api_path = "get_counts")
  records <- nassqs_parse(response)

  # Get the list of allowable values for the parameters 'statisticcat_desc'
  # Equivalent to 'nassqs_param_values("statisticcat_desc")'
  req <- nassqs_GET(list(param = "statisticcat_desc"),
                    api_path = "get_param_values")
  statisticcat_desc_values <- nassqs_parse(req, as = "list")

## End(Not run)

rnassqs documentation built on March 18, 2022, 7:45 p.m.