Skip to content

Commit

Permalink
Merge pull request #41 from bradlindblad/dev
Browse files Browse the repository at this point in the history
Fixing errors with curl, using httr now
  • Loading branch information
bradlindblad authored Dec 3, 2020
2 parents edb3ee4 + b450946 commit 70660f0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
7 changes: 6 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ Imports:
sf,
stringi,
tigris (>= 1.0),
usethis
usethis,
httr,
brio,
waldo,
diffobj,
gitcreds
Suggests:
covr,
knitr,
Expand Down
45 changes: 41 additions & 4 deletions R/getQuickstat.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ defaultCallAPI <- function(key=NULL, program=NULL, data_item=NULL, sector=NULL,
url <- gsub("=,", "=", url)
url <- gsub(" ", "%20", url)

raw <- jsonlite::fromJSON(url)

httr::set_config(httr::config(ssl_verifypeer = 0L))
resp <- httr::GET(url = url)
jsonRespText <- httr::content(resp,as="text", encoding = "UTF-8")


raw <- jsonlite::fromJSON(jsonRespText)
raw <- raw$data
mydata <- raw
return(mydata)
Expand Down Expand Up @@ -88,7 +94,12 @@ multStates <- function(key=NULL, program=NULL, data_item=NULL, sector=NULL, grou
url <- gsub("=,", "=", url)
url <- gsub(" ", "%20", url)

raw <- jsonlite::fromJSON(url)
httr::set_config(httr::config(ssl_verifypeer = 0L))
resp <- httr::GET(url = url)
jsonRespText <- httr::content(resp,as="text", encoding = "UTF-8")


raw <- jsonlite::fromJSON(jsonRespText)
raw <- raw$data
mydata <- raw
return(mydata)
Expand Down Expand Up @@ -140,7 +151,11 @@ multCounties <- function(key=NULL, program=NULL, data_item=NULL, sector=NULL, gr
url <- gsub("=,", "=", url)
url <- gsub(" ", "%20", url)

raw <- jsonlite::fromJSON(url)
httr::set_config(httr::config(ssl_verifypeer = 0L))
resp <- httr::GET(url = url)
jsonRespText <- httr::content(resp,as="text", encoding = "UTF-8")

raw <- jsonlite::fromJSON(jsonRespText)
raw <- raw$data
mydata <- raw
return(mydata)
Expand Down Expand Up @@ -203,7 +218,12 @@ multStatesandCounties <- function(key=NULL, program=NULL, data_item=NULL, sector
url <- gsub("=,", "=", url)
url <- gsub(" ", "%20", url)

raw <- jsonlite::fromJSON(url)
httr::set_config(httr::config(ssl_verifypeer = 0L))
resp <- httr::GET(url = url)
jsonRespText <- httr::content(resp,as="text", encoding = "UTF-8")


raw <- jsonlite::fromJSON(jsonRespText)
raw <- raw$data
mydata <- raw
return(mydata)
Expand Down Expand Up @@ -292,6 +312,23 @@ fuzzyMatch <- function(input, dataset){
getQuickstat <- function(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) {
#
# key <- '7CE0AFAD-EF7B-3761-8B8C-6AF474D6EF71'
# sector=NULL
# group=NULL
# commodity=NULL
# category=NULL
# domain='TOTAL'
# county=NULL
# key = key
# program = 'CENSUS'
# data_item = 'CROP TOTALS - OPERATIONS WITH SALES'
# geographic_level = 'STATE'
# year = '2017'
# state = NULL
# geometry = TRUE
# lower48 = TRUE
# weighted_by_area = T


# Install rgeos if not already installed
Expand Down
2 changes: 1 addition & 1 deletion vignettes/using_tidyusda.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ tidyUSDA::plotUSDA(df = ops.with.sales)

*Note: it is a known issue that the RStudio graphics device on macOS can be extremely laggy when plotting. To get around this, feel free to use your own plotting methods such as the [tmap](https://github.com/mtennekes/tmap) package or [leaflet](https://rstudio.github.io/leaflet/).*

OK wow so it looks like all the farms in the country are in California. But wait a second, California is huge as far as landmass, and the relative size of the farms are smaller on balance, so maybe we should look at this a different way.
OK wow so it looks like all the farms in the country are in Texas But wait a second, Texass is huge as far as landmass, and the relative size of the farms are smaller on balance, so maybe we should look at this a different way.

When we grabbed our data with getQuickstat above, we set weighted_by_area = TRUE, which creates a new field that,as you guessed, weights our main value by the land area in that county or state.

Expand Down

0 comments on commit 70660f0

Please sign in to comment.