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.
Note that the
x.prefix applies toDT2, while thei.prefix applies toDT1, while the user provided them in order(DT1, DT2).At root is that under the hood,
merge(x,y, ...)is constructed as a join withy[x, ...].It would be most consistent with users' expectations of
merge()if the prefixes wereDT1 : x.,DT2: y., or perhaps even better if the errors matchedsuffixes=. A really subtle (and back-incompatible) way to thread the needle here would be to change themerge.data.table()defaults to besuffixes=c(".i", ".x").A different approach (and probably the most practical at this point) is just to emphasize this consideration in the docs.