Error messages from merge() somewhat confusingly "swap" 'x' and 'i' prefixes

Open
#6,641 11 comments 0 reactions 1 assignee View on GitHub

@Abhishek2634 is already working on this.

Since Dec 20, 2024.

Assessment

This issue has not been assessed yet.

Description

documentation
DT1=data.table(a=factor('a'))
DT2=data.table(a=1L)
merge(DT1, DT2, by='a')
# Error in bmerge(i, x, leftcols, rightcols, roll, rollends, nomatch, mult,  : 
#   Incompatible join types: x.a (integer) and i.a (factor). Factor columns must join to factor or character columns.

Note that the x. prefix applies to DT2, while the i. prefix applies to DT1, while the user provided them in order (DT1, DT2).

At root is that under the hood, merge(x,y, ...) is constructed as a join with y[x, ...].

It would be most consistent with users' expectations of merge() if the prefixes were DT1 : x., DT2: y., or perhaps even better if the errors matched suffixes=. A really subtle (and back-incompatible) way to thread the needle here would be to change the merge.data.table() defaults to be suffixes=c(".i", ".x").

A different approach (and probably the most practical at this point) is just to emphasize this consideration in the docs.

Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.