Get data and return a data frameSource:
The primary function in the
nassqs makes a HTTP GET
request to the USDA-NASS Quick Stats API and returns the data parsed as a
data.frame, plain text, or list. Various other functions make use of
to make specific queries. For a data request the Quick Stats API returns
JSON that when parsed to a data.frame contains 39 columns and a varying
number of rows depending on the query. Unfortunately there is not a way to
restrict the number of columns.
nassqs( ..., agg_level_desc = NULL, asd_code = NULL, asd_desc = NULL, begin_code = NULL, class_desc = NULL, commodity_desc = NULL, congr_district_code = NULL, country_code = NULL, country_name = NULL, county_ansi = NULL, county_code = NULL, county_name = NULL, domaincat_desc = NULL, domain_desc = NULL, end_code = NULL, freq_desc = NULL, group_desc = NULL, load_time = NULL, location_desc = NULL, prodn_practice_desc = NULL, reference_period_desc = NULL, region_desc = NULL, sector_desc = NULL, short_desc = NULL, source_desc = NULL, state_alpha = NULL, state_ansi = NULL, state_fips_code = NULL, state_name = NULL, statisticcat_desc = NULL, unit_desc = NULL, util_practice_desc = NULL, watershed_code = NULL, watershed_desc = NULL, week_ending = NULL, year = NULL, zip_5 = NULL, as_numeric = TRUE, progress_bar = TRUE, format = "csv", as = "data.frame" )
either a named list of parameters or a series of additional parameters that include operations, e.g.
year__GE = 2010for all records in 2010 and later. See
detailsfor information on available operators.
Geographic level ("AGRICULTURAL DISTRICT", "COUNTY", "INTERNATIONAL", "NATIONAL", "REGION : MULTI-STATE", "REGION : SUB-STATE", "STATE", "WATERSHED", or "ZIP CODE").
Agriculture statistical district code.
Agriculture statistical district name / description.
Week number indicating when the data series begins.
Commodity, the primary subject of interest (e.g., "CORN", "CATTLE", "LABOR", "TRACTORS", "OPERATORS").
Congressional District codes.
County ANSI code.
County FIPS code.
Domain category within a domain (e.g., under domain_desc = "SALES", domain categories include $1,000 TO $9,999, $10,000 TO $19,999, etc).
Domain, a characteristic of operations that produce a particular commodity (e.g., "ECONOMIC CLASS", "AREA OPERATED", "NAICS CLASSIFICATION", "SALES"). For chemical usage data, the domain describes the type of chemical applied to the commodity. The domain_desc: = "TOTAL" will have no further breakouts; i.e., the data value pertains completely to the short_desc.
= Week number that the data series ends.
Time period type covered by the data ("ANNUAL", "SEASON", "MONTHLY", "WEEKLY", "POINT IN TIME"). "MONTHLY" often covers more than one month. "POINT IN TIME" is for a particular day.
Commodity group within a sector (e.g., under sector_desc = "CROPS", the groups are "FIELD CROPS", "FRUIT & TREE NUTS", "HORTICULTURE", and "VEGETABLES").
Date and time of the data load, e.g. "2015-02-17 16:05:20".
Location code, e.g. 5-digit fips code for counties.
Production practice, (e.g. "UNDER PROTECTION", "OWNED, RIGHTS, LEASED", "ORGANIC, TRANSITIONING", "HIRED MANAGER").
Reference period of the data (e.g. "JUN", "MID SEP", "WEEK #32").
Region name (e.g. "TEXAS", "WA & OR", "WEST COAST", "UMATILLA").
Sector, the five high level, broad categories useful to narrow down choices. ("ANIMALS & PRODUCTS", "CROPS", "DEMOGRAPHICS", "ECONOMICS", or "ENVIRONMENTAL").
A concatenation of six columns:
Source of data ("CENSUS" or "SURVEY"). Census program includes the Census of Ag as well as follow up projects. Survey program includes national, state, and county surveys.
2-character state abbreviation, e.g. "NM".
State ANSI code.
State FIPS code.
Full name of the state, e.g. "ALABAMA".
Statistical category of the data (e.g., "AREA HARVESTED", "PRICE RECEIVED", "INVENTORY", "SALES").
The units of the data (e.g. "TONS / ACRE", "TREES", "OPERATIONS", "NUMBER", "LB / ACRE", "BU / PLANTED ACRE").
Utilization practice (e.g. "WIND", "SUGAR", "SILAGE", "ONCE REFINED", "FEED", "ANIMAL FEED").
Watershed code as 8-digit HUC (e.g. "13020100").
Watershed/HUC name (e.g. "UPPER COLORADO").
Date of ending week (e.g. "1975-11-22").
Year of the data. Conditional values are possible by appending an operation to the parameter, e.g. "year__GE = 2020" will return all records with year >= 2020. See
detailsfor more on operations.
5-digit zip code.
Whether to convert data to numeric format. Conversion will replace missing notation such as "(D)" or "(Z)" with NA, but removes the need to convert to numeric format after querying.
Whether or not to display the progress bar.
The format to return the query in. Only useful if as = "text".
whether to return a data.frame, list, or text string. See
nassqs() accepts all parameters that are accepted by the USDA-NASS Quick
Stats. These parameters are listed in
nassqs_params(), and are used to form
the data query.
Parameters can be modified by operations, which are appended to the parameter name. For example, "year__GE = 2020" will fetch data in 2020 and after. Operations can take the following form:
__LE: less than or equal (<=)
__LT: less than (<)
__GT: greater than (>)
__GE: = >=
__LIKE = like
__NOT_LIKE = not like
__NE = not equal