Skip to content

Commit

Permalink
build out support for DDHCA
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerke committed Sep 21, 2023
1 parent 9fc4404 commit 4e2b008
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Authors@R: c(
person(given = "Kyle", family = "Walker", email="kyle@walker-data.com", role=c("aut", "cre")),
person(given = "Matt", family = "Herman", email = "mfherman@gmail.com", role = "aut"),
person(given = "Kris", family = "Eberwein", email = "eberwein@knights.ucf.edu", role = "ctb"))
Date: 2023-09-14
Date: 2023-09-21
URL: https://walker-data.com/tidycensus/
BugReports: https://github.com/walkerke/tidycensus/issues
Description: An integrated R interface to several United States Census Bureau
Expand Down
14 changes: 13 additions & 1 deletion R/census.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#' @param summary_var Character string of a "summary variable" from the decennial Census
#' to be included in your output. Usually a variable (e.g. total population)
#' that you'll want to use as a denominator or comparison.
#' @param pop_group The population group code for which you'd like to request data. Applies to summary files for which population group breakdowns are available like the Detailed DHC-A file.
#' @param other_args A named list of other keyword arguments to pass to the Census API, if applicable.
#' @param key Your Census API key.
#' Obtain one at \url{https://api.census.gov/data/key_signup.html}
#' @param show_call if TRUE, display call made to Census API. This can be very useful
Expand Down Expand Up @@ -77,6 +79,8 @@ get_decennial <- function(geography,
keep_geo_vars = FALSE,
shift_geo = FALSE,
summary_var = NULL,
pop_group = NULL,
other_args = NULL,
key = NULL,
show_call = FALSE,
...
Expand Down Expand Up @@ -231,6 +235,8 @@ get_decennial <- function(geography,
keep_geo_vars = keep_geo_vars,
shift_geo = FALSE,
summary_var = summary_var,
pop_group = pop_group,
other_args = other_args,
key = key,
show_call = show_call,
...)
Expand Down Expand Up @@ -260,6 +266,8 @@ get_decennial <- function(geography,
keep_geo_vars = keep_geo_vars,
shift_geo = FALSE,
summary_var = summary_var,
pop_group = pop_group,
other_args = other_args,
key = key,
show_call = show_call))
})
Expand Down Expand Up @@ -298,6 +306,8 @@ get_decennial <- function(geography,
message("Using the Demographic and Housing Characteristics File")
} else if (sumfile == "dp") {
message("Using the Demographic Profile")
} else if (sumfile == "ddhca") {
message("Using the Detailed DHC-A File")
}
}
d
Expand Down Expand Up @@ -326,6 +336,8 @@ get_decennial <- function(geography,
message("Using the Demographic and Housing Characteristics File")
} else if (sumfile == "dp") {
message("Using the Demographic Profile")
} else if (sumfile == "ddhca") {
message("Using the Detailed DHC-A File")
}
}

Expand Down Expand Up @@ -445,7 +457,7 @@ get_decennial <- function(geography,
geom <- try(suppressMessages(use_tigris(geography = geography, year = year,
state = state, county = county, criteria = "2020", ...)))
} else if (sumfile == "cd118") {
stop("Geometry is not yet available for this sumfile, but will be in mid-September 2023.")
stop("Geometry is not yet available for this sumfile in tidycensus.")
# try(suppressMessages(use_tigris(geography = geography, year = 2022,
# state = state, county = county, ...)))
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ summary_files <- function(year) {
"gu", "vi", "cd113", "cd113profile",
"cd115", "cd115profile", "cd116")
} else if (year == 2020) {
sumfiles <- c("pl", "dhc", "dp", "pes", "dpas",
sumfiles <- c("pl", "dhc", "dp", "pes", "dpas", "ddhca",
"dpmp", "dpgu", "dpvi",
"dhcvi", "dhcgu", "dhcvi", "dhcas", "cd118")
} else {
Expand Down
12 changes: 8 additions & 4 deletions R/load_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ load_data_acs <- function(geography, formatted_variables, key, year, state = NUL
}


load_data_decennial <- function(geography, variables, key, year, sumfile,
load_data_decennial <- function(geography, variables, key, year, sumfile, pop_group,
other_args,
state = NULL, county = NULL, show_call = FALSE) {


Expand Down Expand Up @@ -405,21 +406,24 @@ load_data_decennial <- function(geography, variables, key, year, sumfile,

call <- GET(base, query = list(get = vars_to_get,
"for" = for_area,
key = key))
key = key,
"POPGROUP" = pop_group))
} else {

call <- GET(base, query = list(get = vars_to_get,
"for" = for_area,
"in" = in_area,
key = key))
key = key,
"POPGROUP" = pop_group))
}
}

else {

call <- GET(base, query = list(get = vars_to_get,
"for" = paste0(geography, ":*"),
key = key))
key = key,
"POPGROUP" = pop_group))
}

if (show_call) {
Expand Down
8 changes: 4 additions & 4 deletions R/search_variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' \code{load_variables()} returns three columns by default: \code{name}, which is the Census ID code to be supplied to the \code{variables} parameter in \code{get_decennial()} or \code{get_acs()}; \code{label}, which is a detailed description of the variable; and \code{concept}, which provides information about the table that a given variable belongs to. For 5-year ACS detailed tables datasets, a fourth column, \code{geography}, tells you the smallest geography at which a given variable is available.
#'
#' Datasets available are as follows: "sf1", "sf2", "sf3", "sf4", "pl", "dhc", "dp",
#' "as", "gu", "mp", "vi", "acsse",
#' "dhca", "ddhca", "as", "gu", "mp", "vi", "acsse",
#' "dpas", "dpgu", "dpmp", "dpvi",
#' "dhcvi", "dhcgu", "dhcvi", "dhcas",
#' "acs1", "acs3", "acs5", "acs1/profile",
Expand Down Expand Up @@ -36,7 +36,7 @@
load_variables <- function(
year,
dataset = c("sf1", "sf2", "sf3", "sf4", "pl", "dhc", "dp",
"as", "gu", "mp", "vi", "acsse",
"ddhca", "as", "gu", "mp", "vi", "acsse",
"dpas", "dpgu", "dpmp", "dpvi",
"dhcvi", "dhcgu", "dhcvi", "dhcas",
"acs1", "acs3", "acs5", "acs1/profile",
Expand Down Expand Up @@ -94,7 +94,7 @@ load_variables <- function(
var_type <- split[2]
}

if (dataset %in% c("sf1", "sf2", "sf3", "sf4", "pl",
if (dataset %in% c("sf1", "sf2", "sf3", "sf4", "pl", "ddhca",
"as", "gu", "mp", "vi", "dhc", "dp",
"dpas", "dpgu", "dpmp", "dpvi",
"dhcvi", "dhcgu", "dhcvi", "dhcas",
Expand Down Expand Up @@ -142,7 +142,7 @@ load_variables <- function(

names(out) <- tolower(names(out))

out1 <- out[grepl("^B[0-9]|^C[0-9]|^DP[0-9]|^S[0-9]|^P.*[0-9]|^H.*[0-9]|^K[0-9]|^CP[0-9]",
out1 <- out[grepl("^B[0-9]|^C[0-9]|^DP[0-9]|^S[0-9]|^P.*[0-9]|^H.*[0-9]|^K[0-9]|^CP[0-9]|^T[0-9]",
out$name), ]

out1$name <- stringr::str_replace(out1$name, "E$|M$", "")
Expand Down
2 changes: 1 addition & 1 deletion man/get_decennial.Rd

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

12 changes: 6 additions & 6 deletions man/load_variables.Rd

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

0 comments on commit 4e2b008

Please sign in to comment.