Unique CSD names
A common task is to get unique names for CSDs. CensusMapper sends down names with the municipal status appended in parenthesis to ward off some duplication of CSD names. A more principled way is to add a column with de-duplicated names in the list_census_regions() call. But that gets out of hand fast, even appending the municipal status does not de-duplicate all names.
A more nuanced approach is to add a dynamic context-depended de-duplication convenience function. For example, if we are looking at Metro Victoria it does not matter that there are a number of other cities called Victoria and we don't need to de-duplicate the name. (Plus there are two Victorias with the same municipal status in different provinces, so appending the municipal status won't de-duplicate the name in this case.)
In v0.5.4 there is a new experimental function add_unique_names_to_region_list() that can be called on the result of a filtered version of list_census_regions() and adds a Name column that is guaranteed to be de-duplicated by appending the municipal status just on the duplicates, and the GeoUID if there are still duplicates left after that.
That way we can de-duplicate depending on context. For example, if one wants to show data for the 9 most populous CSDs within Metro Vancouver, this will give appropriate region names that can be joined onto data by GeoUID.
region <- list_census_regions("CA21") %>%
filter(level=="CSD",CMA_UID=="59933") %>%
add_unique_names_to_region_list() %>%
slice_max(order_by = pop,n=9)
The result looks as follows:
region |> select(region,name,municipal_status,Name)
A tibble: 9 × 4
region name municipal_status Name
1 5915022 Vancouver CY Vancouver
2 5915004 Surrey CY Surrey
3 5915025 Burnaby CY Burnaby
4 5915015 Richmond CY Richmond
5 5915034 Coquitlam CY Coquitlam
6 5915001 Langley DM Langley (DM)
7 5915011 Delta CY Delta
8 5915075 Maple Ridge CY Maple Ridge
9 5915046 North Vancouver DM North Vancouver (DM)
Here North Vancouver and Langley get de-duplicated because within the context of Metro Vancouver there are two CSDs with those names.