Skip to content

Commit

Permalink
fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherkenny committed Feb 26, 2024
1 parent ec4b8c7 commit ec10593
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: censable
Title: Making Census Data More Usable
Version: 0.0.5
Version: 0.0.6
Authors@R:
person(given = "Christopher T.",
family = "Kenny",
Expand All @@ -18,7 +18,7 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
Suggests:
roxygen2,
spelling,
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# censable 0.0.6

* Fixes an error where `build_dec()` and `build_acs()` fail when `geography = 'state'`.

# censable 0.0.4

* Internal changes to `build_dec()` and `build_acs()` to make variable fetching cleaner.
* Adds new `groups` to `build_dec()` for 7 category races with no Hispanic category: `'all7'`, `'pop7'`, and `'vap7'`.
* Allows any part race from `build_dec()` with `'ap:race'` for all race categories.
Expand Down
9 changes: 7 additions & 2 deletions R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ fetch_api_vars_ap <- function(year, group, race) {
get_census_api <- function(geography, year, state, county = NULL,
variables, tab = 'dec/pl', show_call = FALSE) {

state <- match_fips(state)
if (!is.null(state)) {
state <- match_fips(state)
}
rg <- format_regions(geography, state, county, decade = year - (year %% 10))

out <- censusapi::getCensus(
Expand Down Expand Up @@ -137,11 +139,14 @@ format_regions <- function(geography, state, county, decade) {
if (!geography %in% c('state', 'county')) {
rgin <- paste0('state:', state, '+county:', col_var(ct))
rg <- paste0(geography, ':*')
} else if (geography != state) {
} else if (geography != 'state') {
rgin <- paste0('state:', state)
rg <- paste0(geography, ':', col_var(ct))
} else {
rgin <- NULL
if (is.null(state)) {
state <- '*'
}
rg <- paste0('state:', col_var(state))
}

Expand Down
2 changes: 1 addition & 1 deletion R/build_acs.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
#' # uses the Census API
#' tb <- build_acs(geography = 'tract', state = 'NY', county = 'Rockland', geometry = TRUE)
#' }
build_acs <- function(geography, state, county = NULL, geometry = TRUE, year = 2020,
build_acs <- function(geography, state = NULL, county = NULL, geometry = TRUE, year = 2020,
survey = 'acs5', groups = 'all') {
if (!isTRUE(groups[1] %in% c('all', 'pop', 'vap'))) {
groups <- 'all'
Expand Down
5 changes: 3 additions & 2 deletions R/build_dec.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
#' # uses the Census API
#' tb <- build_dec(geography = 'block', state = 'NY', county = 'Rockland', geometry = TRUE)
#' }
build_dec <- function(geography, state, county = NULL, geometry = TRUE,
build_dec <- function(geography, state = NULL, county = NULL, geometry = TRUE,
year = 2020, groups = 'all') {
if (!any(groups %in% c('all', 'pop', 'vap', 'all7', 'pop7', 'vap7') | startsWith(groups, 'ap:'))) {
groups <- 'all'
Expand Down Expand Up @@ -110,7 +110,8 @@ build_dec <- function(geography, state, county = NULL, geometry = TRUE,
groups == 'all' ~ c('pop', 'vap'),
groups == 'all7' ~ c('pop7', 'vap7'),
TRUE ~ groups
) %>% unique()
) %>%
unique()

vars <- lapply(to_get, function(x) fetch_api_vars('dec', year, x))
}
Expand Down
4 changes: 2 additions & 2 deletions man/build_acs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/build_dec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ec10593

Please sign in to comment.