R/hoist_table_glossary.R

Defines functions hoist_table_glossary

Documented in hoist_table_glossary

#' Hoist details about a Census data group from a list of strings to separate columns
#'
#' @param .glossary <data-frame> a table of glossary about Census API variables, e.g. [METADATA_FOR_ACS_VARIABLES]
#' @param .group <chr> the code for the group, e.g. "B01001"
#' @param .fields <chr\[\]> names for the new columns, e.g. c("Sex", "Age")
#'
#' @return a new data frame with more columns
#' @export
#' @concept glossary
#'
#' @examples
#' hoist_table_glossary(METADATA_FOR_ACS_VARIABLES, "B06002", c("Median age", "Place of birth"))
hoist_table_glossary <- function(.glossary, .group, .fields){
    .field_list <- .fields |>
        seq_along() |>
        rlang::set_names(.fields)
    .glossary |>
        dplyr::filter(.data$Group == .group) |>
        tidyr::hoist(.col = "Details", !!!.field_list)
}
higherX4Racine/hercacstables documentation built on Jan. 15, 2025, 9:58 p.m.