@@ -80,9 +80,8 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
8080 if (verbose ) catf(" %s has same type (%s) as %s. No coercion needed.\n " , iname , x_merge_type , xname )
8181 next
8282 }
83- if (x_merge_type == " character" || i_merge_type == " character" ||
84- x_merge_type == " logical" || i_merge_type == " logical" ||
85- x_merge_type == " factor" || i_merge_type == " factor" ) {
83+ cfl = c(" character" , " logical" , " factor" )
84+ if (x_merge_type %chin % cfl || i_merge_type %chin % cfl ) {
8685 if (anyNA(i [[ic ]]) && allNA(i [[ic ]])) {
8786 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 )
8887 set(i , j = ic , value = match.fun(paste0(" as." , x_merge_type ))(i [[ic ]]))
@@ -122,8 +121,7 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
122121 }
123122 if (coerce_x ) {
124123 if (verbose ) catf(" Coercing double column %s (which contains no fractions) to type integer to match type of %s.\n " , iname , xname )
125- val = cast_with_atts(i [[ic ]], as.integer ) # to retain Date for example; 3679
126- set(i , j = ic , value = val )
124+ set(i , j = ic , value = val <- cast_with_atts(i [[ic ]], as.integer )) # to retain Date for example; 3679
127125 set(callersi , j = ic , value = val ) # change the shallow copy of i up in [.data.table to reflect in the result, too.
128126 if (length(ic_idx )> 1L ) {
129127 xc_idx = xcols [ic_idx ]
@@ -140,8 +138,7 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
140138 }
141139 } else {
142140 if (verbose ) catf(" Coercing integer column %s to type double for join to match type of %s.\n " , iname , xname )
143- val = cast_with_atts(i [[ic ]], as.double )
144- set(i , j = ic , value = val )
141+ set(i , j = ic , value = cast_with_atts(i [[ic ]], as.double ))
145142 if (length(ic_idx )> 1L ) {
146143 xc_idx = xcols [ic_idx ]
147144 for (xb in xc_idx [which(vapply_1c(x [0L , xc_idx , with = FALSE ], getClass ) == " integer" )]) {
0 commit comments