Skip to content

Instantly share code, notes, and snippets.

@potterzot
Created May 28, 2019 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save potterzot/757219e35ee84035d002d69a0f8bc133 to your computer and use it in GitHub Desktop.
Save potterzot/757219e35ee84035d002d69a0f8bc133 to your computer and use it in GitHub Desktop.
Fetching PCT PLANTED and YIELD for corn from USDA-NASS QuickStats
### Fetch % planted and yield from NASS QUICKSTATS
#
# Requires the rnassqs `R` package: https://github.com/potterzot/rnassqs
# Need to get an API KEY here: https://quickstats.nass.usda.gov/api
api_key <- Sys.getenv("NASSQS_TOKEN")
## First get PCT PLANTED
# Define the parameters to fetch PCT PLANTED
pct_planted_params <- list(
commodity_desc = "CORN",
agg_level_desc = "STATE",
statisticcat_desc = "PROGRESS",
unit_desc = "PCT PLANTED"
)
# Number of records must be less than 50000
rnassqs::nassqs_record_count(pct_planted_params)
# Fetch the data
pct_planted <- rnassqs::nassqs(pct_planted_params, key = api_key)
## Get YIELD
yield_params <- list(
commodity_desc = "CORN",
agg_level_desc = "STATE",
statisticcat_desc = "YIELD",
unit_desc = "BU / ACRE",
year = "2017"
)
rnassqs::nassqs_record_count(yield_params)
yield <- rnassqs::nassqs(yield_params, key = api_key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment