#' Get census region data at the Canadian level in a tidy format.
#'
#' @param dataset character vector of the data set name (e.g., "CA16")
#' @param query_vector character vector of vector from which to retrieve the data (e.g., "v_CA16_815")
#' @param region_level character vector of which region to aggregate by. Default is "CMA" for Census Metropolitan Area.
#'
#' @return a tidy data frame of region data at the Canadian level
#' @export
#'
#' @examples
#' \dontrun{
#' library(canlang)
#' options(cancensus.api_key = "your_api_key")
#' get_region_data("CA16", "v_CA16_563")
#' }
get_region_data <- function(dataset, query_vector, region_level = "CMA") {
langs <- cancensus::list_census_vectors(dataset) %>%
dplyr::filter(vector == query_vector)
langs_children <- langs %>%
cancensus::child_census_vectors(TRUE)
langs_vectors <- dplyr::bind_rows(langs, langs_children) %>%
dplyr::pull(vector)
region <- cancensus::list_census_regions(dataset, use_cache = FALSE) %>%
dplyr::filter(level == region_level) %>%
cancensus::as_census_region_list()
language <- cancensus::get_census(dataset = dataset,
regions = region,
vectors = langs_vectors,
level = region_level) %>%
dplyr::select(`Region Name`, Households,`Area (sq km)`, Population, Dwellings) %>%
dplyr::arrange(Population) %>%
dplyr::rename(households = Households,
area = `Area (sq km)`,
population = Population,
dwellings = Dwellings)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.