ropensci / rnassqs

R interface for the USDA National Agricultural Statistical Service's (NASS) 'Quick Stats' API (https://quickstats.nass.usda.gov/api)
https://docs.ropensci.org/rnassqs
Other
46 stars 18 forks source link

Updated query syntax #27

Closed RafaRafa closed 3 years ago

RafaRafa commented 4 years ago

Hi, before a certain update I used to be able to pass a paramter like this:

x = c(year = "2019", year = "2020", year = "2021", short_desc = "CORN - ACRES PLANTED")

under version 2.2 a call using rnassqs_GET(params = x) would work.

I tried making

x = list(year = 2019:2021, short_desc = "CORN - ACRES PLANTED") but this fails with

Error in data.frame(values = unlist(unname(x)), ind, stringsAsFactors = FALSE) : arguments imply differing number of rows: 5, 3

What's the equivalent call to the one above? Querying a specific number of years?

Thanks

potterzot commented 4 years ago

Hi @RafaRafa - The syntax changed slightly as part of the rOpenSci review process, so that now instead of

x <- list(year = 2019:2021, short_desc = "CORN - ACRES PLANTED")
nassqs(params = x)

The same call is instead:

# Note no "params = " anymore.
nassqs(x)

I just tested this and had no trouble, please let me know if that doesn't work for you.

The reason is that this way instead of passing a list, individual parameters can be passed as arguments to the function, but it was a breaking syntax change from earlier versions unfortunately.