Skip to content

[feature request] diagnostic for merge.data.table when by = key is not present in dt being merged #6556

@zhizhongpu

Description

@zhizhongpu

# Minimal reproducible example; please be sure to set verbose=TRUE where possible!

When merging two dt using merge.data.table and the key is not present in one of the two dts, data.table throws out an uninformative error:

Error in merge.data.table(test, manual, by = c("iso3c", "year"), all = T) : 
  Elements listed in `by` must be valid column names in x and y

which is not helpful as the user would then have to debug which key is not present in which dt. A more informative error would list all keys not present in all dts. For example:

> combined = test |> 
+   left_join(manual, by = c('iso3c', 'year')) 
Error in `left_join()`:
! Join columns in `y` must be present in the
  data.
✖ Problem with `iso3c`.

# Output of sessionInfo()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions