Skip to content

Commit

Permalink
modularize more
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-schwen committed Nov 27, 2024
1 parent 69a7b20 commit 3023b5c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions R/bmerge.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,13 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
}
cfl = c("character", "logical", "factor")
if (x_merge_type %chin% cfl || i_merge_type %chin% cfl) {
msg = "Coercing all-NA %s column %s to type %s to match type of %s.\n"
if (anyNA(i[[ic]]) && allNA(i[[ic]])) {
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)
set(i, j=ic, value=match.fun(paste0("as.", x_merge_type))(i[[ic]]))
coerce_col(i, ic, i_merge_type, x_merge_type, iname, xname, msg)
next
}
if (anyNA(x[[xc]]) && allNA(x[[xc]])) {
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)
set(x, j=xc, value=match.fun(paste0("as.", i_merge_type))(x[[xc]]))
coerce_col(x, xc, x_merge_type, i_merge_type, xname, iname, msg)
next
}
stopf("Incompatible join types: %s (%s) and %s (%s)", xname, x_merge_type, iname, i_merge_type)
Expand Down
6 changes: 3 additions & 3 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -15156,15 +15156,15 @@ if (test_bit64) {
dt1 = data.table(a=1, b=NA_character_)
dt2 = data.table(a=2L, b=NA)
test(2044.80, dt1[dt2, on="a==b", verbose=TRUE], data.table(a=NA, b=NA_character_, i.a=2L),
output=msg<-"Coercing all-NA i.b (logical) to type double to match type of x.a")
output=msg<-"Coercing all-NA logical column i.b to type double to match type of x.a")
test(2044.81, dt1[dt2, on="a==b", nomatch=0L, verbose=TRUE], data.table(a=logical(), b=character(), i.a=integer()),
output=msg)
test(2044.82, dt1[dt2, on="b==b", verbose=TRUE], data.table(a=1, b=NA, i.a=2L),
output=msg<-"Coercing all-NA i.b (logical) to type character to match type of x.b")
output=msg<-"Coercing all-NA logical column i.b to type character to match type of x.b")
test(2044.83, dt1[dt2, on="b==b", nomatch=0L, verbose=TRUE], data.table(a=1, b=NA, i.a=2L),
output=msg)
test(2044.84, dt1[dt2, on="b==a", verbose=TRUE], data.table(a=NA_real_, b=2L, i.b=NA),
output=msg<-"Coercing all-NA x.b (character) to type integer to match type of i.a")
output=msg<-"Coercing all-NA character column x.b to type integer to match type of i.a")
test(2044.85, dt1[dt2, on="b==a", nomatch=0L, verbose=TRUE], data.table(a=double(), b=integer(), i.b=logical()),
output=msg)

Expand Down

0 comments on commit 3023b5c

Please sign in to comment.