Skip to content

Commit

Permalink
print informative error message if API key is invalid or inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerke committed Oct 16, 2018
1 parent 8bcd2b8 commit 7173758
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
@@ -1,11 +1,11 @@
Package: tidycensus
Type: Package
Title: Load US Census Boundary and Attribute Data as 'tidyverse' and 'sf'-Ready Data Frames
Version: 0.8.2
Version: 0.8.3
Authors@R: c(
person(given = "Kyle", family = "Walker", email="kyle.walker@tcu.edu", role=c("aut", "cre")),
person(given = "Kris", family = "Eberwein", email = "eberwein@knights.ucf.edu", role = "ctb"))
Date: 2018-09-27
Date: 2018-10-16
URL: https://github.com/walkerke/tidycensus
BugReports: https://github.com/walkerke/tidycensus/issues
Description: An integrated R interface to the decennial US Census and American Community Survey APIs and
Expand Down
12 changes: 12 additions & 0 deletions R/load_data.R
Expand Up @@ -232,6 +232,10 @@ load_data_acs <- function(geography, formatted_variables, key, year, state = NUL

content <- content(call, as = "text")

if (grepl("You included a key with this request", content)) {
stop("You have supplied an invalid or inactive API key. To obtain a valid API key, visit https://api.census.gov/data/key_signup.html. To activate your key, be sure to click the link provided to you in the email from the Census Bureau that contained your key.", call. = FALSE)
}

dat <- tbl_df(fromJSON(content))

colnames(dat) <- dat[1,]
Expand Down Expand Up @@ -376,6 +380,10 @@ load_data_decennial <- function(geography, variables, key, year,

content <- content(call, as = "text")

if (grepl("You included a key with this request", content)) {
stop("You have supplied an invalid or inactive API key. To obtain a valid API key, visit https://api.census.gov/data/key_signup.html. To activate your key, be sure to click the link provided to you in the email from the Census Bureau that contained your key.", call. = FALSE)
}

# Fix issue in SF3 2000 API - https://github.com/walkerke/tidycensus/issues/22
if (year == 2000 && sumfile == "sf3") {
content <- str_replace(content, 'O"Brien', "O'Brien")
Expand Down Expand Up @@ -555,6 +563,10 @@ load_data_estimates <- function(geography, product = NULL, variables = NULL,

content <- content(call, as = "text")

if (grepl("You included a key with this request", content)) {
stop("You have supplied an invalid or inactive API key. To obtain a valid API key, visit https://api.census.gov/data/key_signup.html. To activate your key, be sure to click the link provided to you in the email from the Census Bureau that contained your key.", call. = FALSE)
}

dat <- tbl_df(fromJSON(content))

colnames(dat) <- dat[1,]
Expand Down

0 comments on commit 7173758

Please sign in to comment.