R/latest_acs_metadata.R

Defines functions latest_acs_metadata

Documented in latest_acs_metadata

#' Download glossary about the most recent versions of the 1- and 5-year ACS
#'
#' @param information_type <chr> "geographies", "groups", or "variables"
#'
#' @return a tibble with dimensions that depend upon `information_type`
#' @export
#' @concept glossary
latest_acs_metadata <- function(information_type) {
    rlang::arg_match(
        information_type,
        c("geography", "groups", "variables")
    )

    .this_year <- as.POSIXlt(Sys.Date())$year + 1900L

    .GLOSSARY_OF_RAW_ACS_GROUP <- tibble::tibble(
        .year_span = c(1L, 5L),
        .info_type = information_type
    ) |>
        dplyr::mutate(
            .year = purrr::map_int(.data$.year_span,
                                   \(.ys) most_recent_vintage(
                                       "acs",
                                       paste0("acs", .ys)
                    )),
            Glossary = purrr::pmap(dplyr::pick(tidyselect::everything()),
                                   fetch_metadata_table),
            Dataset = paste0("ACS", .data$.year_span)
        ) |>
        dplyr::select(
            c("Dataset", "Glossary")
        ) |>
        tidyr::unnest(
            "Glossary"
        )
}
higherX4Racine/hercacstables documentation built on Jan. 15, 2025, 9:58 p.m.