From cb3a726c189d929787a767b6889cbae56b9764e8 Mon Sep 17 00:00:00 2001 From: your name Date: Sun, 9 Jun 2024 22:25:30 -0400 Subject: [PATCH] Add reliability support to get_acs_tables --- R/get_acs_ext.R | 21 +++++++++++++++++++-- man/get_acs_metadata.Rd | 8 +++++--- man/get_acs_tables.Rd | 7 +++++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/R/get_acs_ext.R b/R/get_acs_ext.R index daa1c3e..0a41e46 100644 --- a/R/get_acs_ext.R +++ b/R/get_acs_ext.R @@ -135,10 +135,12 @@ get_acs_tables <- function(geography, year = 2022, survey = "acs5", variables = NULL, + moe_level = 90, ..., crs = NULL, label = TRUE, perc = TRUE, + reliability = FALSE, keep_geography = TRUE, geoid_col = "GEOID", quiet = FALSE, @@ -156,7 +158,12 @@ get_acs_tables <- function(geography, variable_labels <- NULL if (is_character(variables) && is_named(variables)) { - variable_labels <- tibble::enframe(variables, name = "variable", value = "variable_id") + variable_labels <- tibble::enframe( + variables, + name = "variable", + value = "variable_id" + ) + variable_col <- "variable_id" } @@ -185,6 +192,7 @@ get_acs_tables <- function(geography, year = year, survey = survey, variables = variables, + moe_level = moe_level, ..., .fn = .fn, .call = call @@ -193,9 +201,16 @@ get_acs_tables <- function(geography, acs_data <- list_rbind(acs_list) if (keep_geography) { + geography_cols <- as.data.frame( + do.call( + cbind, + get_geography_params(geography = geography, year = year, ...) + ) + ) + acs_data <- vctrs::vec_cbind( acs_data, - as.data.frame(do.call(cbind, get_geography_params(geography = geography, year = year, ...))), + geography_cols, .error_call = call ) } @@ -233,6 +248,8 @@ get_acs_tables <- function(geography, survey = survey, year = year, perc = perc, + reliability = reliability, + moe_level = moe_level, geoid_col = geoid_col, variable_col = variable_col ) diff --git a/man/get_acs_metadata.Rd b/man/get_acs_metadata.Rd index c7215cd..7acc980 100644 --- a/man/get_acs_metadata.Rd +++ b/man/get_acs_metadata.Rd @@ -88,7 +88,7 @@ character represents one column: By default, reading a file without a column specification will print a message showing what \code{readr} guessed they were. To remove this message, -set \code{show_col_types = FALSE} or set `options(readr.show_col_types = FALSE).} +set \code{show_col_types = FALSE} or set \code{options(readr.show_col_types = FALSE)}.} \item{\code{col_select}}{Columns to include in the results. You can use the same mini-language as \code{dplyr::select()} to refer to the columns by name. Use \code{c()} to use more than one selection expression. Although this @@ -125,9 +125,11 @@ supported: \itemize{ \item \code{"minimal"}: No name repair or checks, beyond basic existence of names. \item \code{"unique"} (default value): Make sure names are unique and not empty. -\item \code{"check_unique"}: no name repair, but check they are \code{unique}. +\item \code{"check_unique"}: No name repair, but check they are \code{unique}. +\item \code{"unique_quiet"}: Repair with the \code{unique} strategy, quietly. \item \code{"universal"}: Make the names \code{unique} and syntactic. -\item A function: apply custom name repair (e.g., \code{name_repair = make.names} +\item \code{"universal_quiet"}: Repair with the \code{universal} strategy, quietly. +\item A function: Apply custom name repair (e.g., \code{name_repair = make.names} for names in the style of base R). \item A purrr-style anonymous function, see \code{\link[rlang:as_function]{rlang::as_function()}}. } diff --git a/man/get_acs_tables.Rd b/man/get_acs_tables.Rd index 779b457..8653f91 100644 --- a/man/get_acs_tables.Rd +++ b/man/get_acs_tables.Rd @@ -13,10 +13,12 @@ get_acs_tables( year = 2022, survey = "acs5", variables = NULL, + moe_level = 90, ..., crs = NULL, label = TRUE, perc = TRUE, + reliability = FALSE, keep_geography = TRUE, geoid_col = "GEOID", quiet = FALSE, @@ -84,6 +86,9 @@ expressed as "acs1", "acs3", and "acs5". The default selection is "acs5."} IDs. tidycensus automatically returns the estimate and the margin of error associated with the variable.} +\item{moe_level}{The confidence level of the returned margin of error. One +of 90 (the default), 95, or 99.} + \item{...}{ Arguments passed on to \code{\link[tidycensus:get_acs]{tidycensus::get_acs}} \describe{ @@ -109,8 +114,6 @@ be included in your output. Usually a variable (e.g. total population) that you'll want to use as a denominator or comparison.} \item{\code{key}}{Your Census API key. Obtain one at \url{https://api.census.gov/data/key_signup.html}} - \item{\code{moe_level}}{The confidence level of the returned margin of error. One -of 90 (the default), 95, or 99.} \item{\code{show_call}}{if TRUE, display call made to Census API. This can be very useful in debugging and determining if error messages returned are due to tidycensus or the Census API. Copy to the API call into a browser and see