Skip to content

Commit 0158272

Browse files
restore factor checks as coming first
1 parent b4a3e72 commit 0158272

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

R/bmerge.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
6666
iname = paste0("i.", names(i)[icol])
6767
if (!x_merge_type %chin% supported) stopf("%s is type %s which is not supported by data.table join", xname, x_merge_type)
6868
if (!i_merge_type %chin% supported) stopf("%s is type %s which is not supported by data.table join", iname, i_merge_type)
69-
if (x_merge_type == i_merge_type) {
70-
if (verbose) catf("%s has same type (%s) as %s. No coercion needed.\n", iname, x_merge_type, xname)
71-
next
72-
}
69+
# we check factors first because they might have different levels
7370
if (x_merge_type=="factor" || i_merge_type=="factor") {
7471
if (x_merge_type=="factor" && i_merge_type=="factor") {
7572
if (verbose) catf("Matching %s factor levels to %s factor levels.\n", iname, xname)
@@ -91,6 +88,10 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
9188
}
9289
stopf("Incompatible join types: %s (%s) and %s (%s). Factor columns must join to factor or character columns.", xname, x_merge_type, iname, i_merge_type)
9390
}
91+
if (x_merge_type == i_merge_type) {
92+
if (verbose) catf("%s has same type (%s) as %s. No coercion needed.\n", iname, x_merge_type, xname)
93+
next
94+
}
9495
cfl = c("character", "logical", "factor")
9596
if (x_merge_type %chin% cfl || i_merge_type %chin% cfl) {
9697
msg = if(verbose) gettext("Coercing all-NA %s column %s to type %s to match type of %s.\n") else NULL

0 commit comments

Comments
 (0)