diff --git a/R/bmerge.R b/R/bmerge.R index b661cd47a7..d0c5c63a8e 100644 --- a/R/bmerge.R +++ b/R/bmerge.R @@ -32,7 +32,7 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos ans } - for (a in seq_along(icols)) { + if (nrow(i)) for (a in seq_along(icols)) { # - check that join columns have compatible types # - do type coercions if necessary on just the shallow local copies for the purpose of join # - handle factor columns appropriately diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index bd8b2abb51..1c65a6ebbc 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -15920,6 +15920,10 @@ test(2100.12, fifelse(c(TRUE,FALSE,TRUE,TRUE,FALSE,NA), factor(letters[1:6]), fa test(2100.13, lapply(list(list(yes = 1, no = 2, na = 3), list(yes = 2, no = 4)), function(el) fifelse(c(TRUE, FALSE, NA), el$yes, el$no, el$na)), list(c(1,2,3),c(2,4,NA))) test(2100.14, fifelse(c(T,F,NA),c(1,1,1),c(2,2,2),NA), c(1,2,NA)) +# join 0-row i type mismatch ok to coerce, tcpl #3581 +DT = data.table(id=1:3, v=4:6, key="id") +test(2101, DT[.(logical())], data.table(id=logical(), v=integer(), key="id")) + ################################### # Add new tests above this line # diff --git a/src/bmerge.c b/src/bmerge.c index 47bf74ed38..510ec434f3 100644 --- a/src/bmerge.c +++ b/src/bmerge.c @@ -60,7 +60,7 @@ SEXP bmerge(SEXP iArg, SEXP xArg, SEXP icolsArg, SEXP xcolsArg, SEXP isorted, SE if (xcols[col]>LENGTH(x) || xcols[col]<1) error("xcols[%d]=%d outside range [1,length(x)=%d]", col, xcols[col], LENGTH(x)); int it = TYPEOF(VECTOR_ELT(i, icols[col]-1)); int xt = TYPEOF(VECTOR_ELT(x, xcols[col]-1)); - if (it != xt) error("typeof x.%s (%s) != typeof i.%s (%s)", CHAR(STRING_ELT(getAttrib(x,R_NamesSymbol),xcols[col]-1)), type2char(xt), CHAR(STRING_ELT(getAttrib(i,R_NamesSymbol),icols[col]-1)), type2char(it)); + if (iN && it!=xt) error("typeof x.%s (%s) != typeof i.%s (%s)", CHAR(STRING_ELT(getAttrib(x,R_NamesSymbol),xcols[col]-1)), type2char(xt), CHAR(STRING_ELT(getAttrib(i,R_NamesSymbol),icols[col]-1)), type2char(it)); } // raise(SIGINT);