R/unpack_group_details.R

Defines functions unpack_group_details

Documented in unpack_group_details

#' Pull apart the lists of details for one group of ACS data
#'
#' @param .group the code of the group, like "B25043" or "C15010B"
#'
#' @return a tibble with at least 4 columns, like [hercacstables::METADATA_FOR_ACS_VARIABLES], but `Details` is split into multiple columns with uppercase letter names.
#' @export
#'
#' @examples
#' unpack_group_details("B01002B")
#'
#' @seealso [METADATA_FOR_ACS_VARIABLES]
unpack_group_details <- function(.group) {
    hercacstables::METADATA_FOR_ACS_VARIABLES |>
        dplyr::filter(
            .data$Group == .group
        ) |>
        dplyr::mutate(
            Details = purrr::map(.data$Details,
                                 \(.d) tibble::tibble(
                                     Column = LETTERS[seq_along(.d)],
                                     Detail = .d
                                 )
            )
        ) |>
        tidyr::unnest(
            cols = "Details"
        ) |>
        tidyr::pivot_wider(
            names_from = "Column",
            values_from = "Detail",
            values_fill = ""
        )
}
higherX4Racine/hercacstables documentation built on Jan. 15, 2025, 9:58 p.m.