Skip to content

Commit

Permalink
Merge pull request #18 from transportfoundry/develop
Browse files Browse the repository at this point in the history
Close develop
  • Loading branch information
gregmacfarlane authored Jul 6, 2016
2 parents 1c0a19c + c841157 commit 81470d0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Package: censusr
Type: Package
Title: Collect Data from the Census API
Version: 0.0.2
Version: 0.0.2.9000
Date: 2015-12-11
Authors@R: c(
person("Greg", "Macfarlane", email = "[email protected]", role = c("cre", "aut")),
person("Josie", "Kressner", email = "[email protected]", role = "aut"))
Description: Use the US Census API to collect summary data tables
for SF1 and ACS datasets at arbitrary geographies.
URL: https://github.com/transportfoundry/censusr
BugReports: https://github.com/transportfoundry/censusr/issues
License: MIT + file LICENSE
LazyData: TRUE
Depends:
Expand Down
11 changes: 10 additions & 1 deletion R/call_census_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ call_census_api <- function(variables_to_get,
year = 2013, period = 5,
api_key = NULL){

data_source <- match.arg(data_source)

if (stringr::str_sub(variables_to_get, -1, -1) %in% c("E", "M") &
data_source != "acs") {
stop('Your variables look like ACS variables. You have specified, or the call has defaulted to, the decennial census. Set `data_source = "acs"` in the function call.')
}

if(Sys.getenv("CENSUS_TOKEN") == "" && is.null(api_key)){
stop("censusr requires an API key. Request one at http://api.census.gov/data/key_signup.html")
}
Expand Down Expand Up @@ -116,7 +123,9 @@ call_api_once <- function(variables_to_get, geoid, allgeos, data_source, year,
url <- paste0(call_start, var_string, geo_string, api_string)

# gives back a list of lists; convert to dataframe
response <- httr::content(httr::GET(url))
r <- httr::GET(url)
httr::stop_for_status(r)
response <- httr::content(r)

df <- data.frame(t(sapply(response, c)), stringsAsFactors = F)[-1,]
names(df) <- response[[1]]
Expand Down
2 changes: 1 addition & 1 deletion vignettes/censusr.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ author: ""
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Vignette Title}
%\VignetteIndexEntry{censusr}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down

0 comments on commit 81470d0

Please sign in to comment.