Skip to contents

Get values from USDA Quick Stats in a dataframe with optional sf (simple features) geometry field

Usage

getQuickstat(
  key = NULL,
  program = NULL,
  data_item = NULL,
  sector = NULL,
  group = NULL,
  commodity = NULL,
  category = NULL,
  domain = NULL,
  geographic_level = NULL,
  state = NULL,
  county = NULL,
  year = NULL,
  geometry = FALSE,
  lower48 = FALSE,
  weighted_by_area = FALSE
)

Arguments

key

your USDA api key. Get one at https://quickstats.nass.usda.gov/api - string

program

program field - string

data_item

data_item field - string

sector

sector field - string

group

group field - string

commodity

commodity field - string

category

category field - string

domain

domain field - string

geographic_level

geographic_level field - string

state

state field - either a string or character vector with multiple states

county

county field - either a string or character vector with multiple states

year

year field - string

geometry

geometry field (TRUE or FALSE), set to TRUE if you would like a simple features (SF) geometry field included. Only works when geographic_level is set to 'COUNTY' or 'STATE'

lower48

limit data to the lower 48 states? - TRUE or FALSE

weighted_by_area

option to mutate a new column that takes the target ('Value') and divides it by the square miles in that state or county; only works when GEOMETRY = TRUE - TRUE or FALSE

Note

Go to the webpage https://quickstats.nass.usda.gov/. As a best practice, select the items in these fields and test that that data item exists in the browser before using those parameters in this function. When you have a dataset that works, enter those values in the function as parameters. Ideally, only enter values for your key obviously, then PROGRAM, DATA_ITEM, GEOGRAPHIC_LEVEL and then if necessary, DOMAIN, STATE, COUNTY or YEAR.

Examples

if (FALSE) {
getQuickstat(
  key = "your_key",
  program = "CENSUS",
  data_item = "CROP TOTALS - OPERATIONS WITH SALES",
  geographic_level = "COUNTY",
  domain = "TOTAL",
  year = "2017",
  state = NULL,
  geometry = T,
  lower48 = T
)
}