Skip to content

Commit 3023b5c

Browse files
committed
modularize more
1 parent 69a7b20 commit 3023b5c

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

R/bmerge.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,13 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
8787
}
8888
cfl = c("character", "logical", "factor")
8989
if (x_merge_type %chin% cfl || i_merge_type %chin% cfl) {
90+
msg = "Coercing all-NA %s column %s to type %s to match type of %s.\n"
9091
if (anyNA(i[[ic]]) && allNA(i[[ic]])) {
91-
if (verbose) catf("Coercing all-NA %s (%s) to type %s to match type of %s.\n", iname, i_merge_type, x_merge_type, xname)
92-
set(i, j=ic, value=match.fun(paste0("as.", x_merge_type))(i[[ic]]))
92+
coerce_col(i, ic, i_merge_type, x_merge_type, iname, xname, msg)
9393
next
9494
}
9595
if (anyNA(x[[xc]]) && allNA(x[[xc]])) {
96-
if (verbose) catf("Coercing all-NA %s (%s) to type %s to match type of %s.\n", xname, x_merge_type, i_merge_type, iname)
97-
set(x, j=xc, value=match.fun(paste0("as.", i_merge_type))(x[[xc]]))
96+
coerce_col(x, xc, x_merge_type, i_merge_type, xname, iname, msg)
9897
next
9998
}
10099
stopf("Incompatible join types: %s (%s) and %s (%s)", xname, x_merge_type, iname, i_merge_type)

inst/tests/tests.Rraw

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15156,15 +15156,15 @@ if (test_bit64) {
1515615156
dt1 = data.table(a=1, b=NA_character_)
1515715157
dt2 = data.table(a=2L, b=NA)
1515815158
test(2044.80, dt1[dt2, on="a==b", verbose=TRUE], data.table(a=NA, b=NA_character_, i.a=2L),
15159-
output=msg<-"Coercing all-NA i.b (logical) to type double to match type of x.a")
15159+
output=msg<-"Coercing all-NA logical column i.b to type double to match type of x.a")
1516015160
test(2044.81, dt1[dt2, on="a==b", nomatch=0L, verbose=TRUE], data.table(a=logical(), b=character(), i.a=integer()),
1516115161
output=msg)
1516215162
test(2044.82, dt1[dt2, on="b==b", verbose=TRUE], data.table(a=1, b=NA, i.a=2L),
15163-
output=msg<-"Coercing all-NA i.b (logical) to type character to match type of x.b")
15163+
output=msg<-"Coercing all-NA logical column i.b to type character to match type of x.b")
1516415164
test(2044.83, dt1[dt2, on="b==b", nomatch=0L, verbose=TRUE], data.table(a=1, b=NA, i.a=2L),
1516515165
output=msg)
1516615166
test(2044.84, dt1[dt2, on="b==a", verbose=TRUE], data.table(a=NA_real_, b=2L, i.b=NA),
15167-
output=msg<-"Coercing all-NA x.b (character) to type integer to match type of i.a")
15167+
output=msg<-"Coercing all-NA character column x.b to type integer to match type of i.a")
1516815168
test(2044.85, dt1[dt2, on="b==a", nomatch=0L, verbose=TRUE], data.table(a=double(), b=integer(), i.b=logical()),
1516915169
output=msg)
1517015170

0 commit comments

Comments
 (0)