This function ensures that all columns in a dm have unique names.

dm_disambiguate_cols(dm, sep = ".", quiet = FALSE)

Arguments

dm

A dm object.

sep

The character variable that separates the names of the table and the names of the ambiguous columns.

quiet

Boolean. By default, this function lists the renamed columns in a message, pass TRUE to suppress this message.

Value

A dm whose column names are unambiguous.

Details

The function first checks if there are any column names that are not unique. If there are, those columns will be assigned new, unique, names by prefixing their existing name with the name of their table and a separator. Columns that act as primary or foreign keys will not be renamed because only the foreign key column will remain when two tables are joined, making that column name "unique" as well.

Examples

dm_nycflights13() %>% dm_disambiguate_cols()
#> Renamed columns: #> * name -> airlines.name, airports.name #> * year -> flights.year, planes.year, weather.year #> * month -> flights.month, weather.month #> * day -> flights.day, weather.day #> * origin -> flights.origin, weather.origin #> * hour -> flights.hour, weather.hour #> * time_hour -> flights.time_hour, weather.time_hour
#> ── Metadata ──────────────────────────────────────────────────────────────────── #> Tables: `airlines`, `airports`, `flights`, `planes`, `weather` #> Columns: 53 #> Primary keys: 3 #> Foreign keys: 3