Skip to content

Commit 3218515

Browse files
committed
do not match.fun as.integer64, pull 'factor' cond from cast_with_atts to coerce_col
1 parent e275acf commit 3218515

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

R/bmerge.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ mergeType = function(x) {
1111

1212
cast_with_atts = function(x, as.f) {
1313
ans = as.f(x)
14-
# do not copy attributes when coercing factor (to character)
15-
if (!is.factor(x) && !is.null(attributes(x))) attributes(ans) = attributes(x)
14+
if (!is.null(attributes(x))) attributes(ans) = attributes(x)
1615
ans
1716
}
1817

@@ -21,7 +20,9 @@ coerce_col = function(dt, col, from_type, to_type, from_name, to_name, from_deta
2120
"Coercing %s column %s%s to type %s to match type of %s%s.\n",
2221
from_type, from_name, from_detail, to_type, to_name, to_detail
2322
)
24-
set(dt, j=col, value=cast_with_atts(dt[[col]], match.fun(paste0("as.", to_type))))
23+
as.f = switch(to_type, integer64 = bit64::as.integer64, match.fun(paste0("as.", to_type)))
24+
# do not copy attributes when coercing factor (to character)
25+
set(dt, j=col, value = if (is.factor(dt[[col]])) as.f(dt[[col]]) else cast_with_atts(dt[[col]], as.f))
2526
}
2627

2728
bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbose)

0 commit comments

Comments
 (0)