#' Summarize Population Demopgraphics
#'
#' @param cols `character`. The column(s) to summarize.
#'
#' @return A `tibble` with a column for each
#' `cols` (`int` of `cols = "age"`, `fct` otherwise) and corresponding
#' `population` (`int`)
#'
#' @keywords internal
count_pop <- function(cols = c("age", "sex", "race", "ethnicity"), peds = FALSE) {
assert_bool(peds)
# Force evaluation to avoid a {tidyselect} warning below
force(cols)
cols <- as.list(select_colnames(covidReport::pop_2019, {{ cols }}))
cols <- rlang::syms(cols)
covidReport::pop_2019 %>%
purrr::when(peds ~ dplyr::filter(., .data[["age"]] < 18L), ~ .) %>%
dplyr::group_by(!!!cols) %>%
dplyr::summarize(n = sum(.data[["population"]], na.rm = TRUE)) %>%
dplyr::ungroup()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.