Returns a data frame, list, or text string. If a data.frame, all columns except year strings because the 'Quick Stats' data returns suppressed data as '(D)', '(Z)', or other character indicators which mean different things. Converting the value to a numerical results in NA, which loses that information.

nassqs_parse(req, as = c("data.frame", "list", "text"), ...)

Arguments

req

the GET response from nassqs_GET()

as

whether to return a data.frame, list, or text string

...

additional parameters passed to jsonlite::fromJSON() or utils::read.csv()

Value

a data frame, list, or text string of the content from the response.

Examples

# Set parameters and make the request params <- list(commodity_name = "CORN", year = 2012, agg_level_desc = "STATE", state_alpha = "WA", statisticcat_desc = "YIELD") response <- nassqs_GET(params)
#> | | | 0% | |======================================================================| 100%
#> Error: HTTP Failure: 401 #> unauthorized
# Parse the response to a data frame corn <- nassqs_parse(response, as = "data.frame")
#> Error in nassqs_parse(response, as = "data.frame"): object 'response' not found
head(corn)
#> Error in head(corn): object 'corn' not found
# Parse the response into a raw character string. corn_text<- nassqs_parse(response, as = "text")
#> Error in nassqs_parse(response, as = "text"): object 'response' not found
head(corn_text)
#> Error in head(corn_text): object 'corn_text' not found
# Get a list of parameter values and parse as a list response <- nassqs_GET(list(param = "statisticcat_desc"), api_path = "get_param_values")
#> | | | 0% | |======================================================================| 100%
#> Error: HTTP Failure: 401 #> unauthorized
statisticcat_desc_values <- nassqs_parse(response, as = "list")
#> Error in nassqs_parse(response, as = "list"): object 'response' not found
head(statisticcat_desc_values)
#> Error in head(statisticcat_desc_values): object 'statisticcat_desc_values' not found