USAboundaries icon indicating copy to clipboard operation
USAboundaries copied to clipboard

Duplicate column names in us_counties()

Open Joe-Wasserman opened this issue 3 years ago • 0 comments

The object returned by us_counties() has two columns named state_name, which causes problems for functions that require unique names. make.names(unique = TRUE) makes all of the names unique.

Reprex:

usCounties <- USAboundaries::us_counties()
dplyr::left_join(usCounties, usCounties)
#> Error in `dplyr::left_join()`:
#> ! Input columns in `x` must be unique.
#> ✖ Problem with `state_name`.
usCountiesNames <- names(usCounties) |> make.names(unique = TRUE)
usCountiesUniqueNames <- purrr::set_names(usCounties, usCountiesNames)
dplyr::left_join(usCountiesUniqueNames, usCountiesUniqueNames)
#> Joining, by = c("statefp", "countyfp", "countyns", "affgeoid", "geoid", "name",
#> "namelsad", "stusps", "state_name", "lsad", "aland", "awater", "state_name.1",
#> "state_abbr", "jurisdiction_type", "geometry")
#> Error:
#> ! All columns in a tibble must be vectors.
#> ✖ Column `geometry` is a `sfc_MULTIPOLYGON/sfc` object.
#> 
#> Note that this second error is different and can only occur because the error with non-unique column names has been resolved.

Created on 2022-07-28 by the reprex package (v2.0.1)

Joe-Wasserman avatar Jul 28 '22 14:07 Joe-Wasserman