Skip to content

Commit

Permalink
do not match.fun as.integer64, pull 'factor' cond from cast_with_atts…
Browse files Browse the repository at this point in the history
… to coerce_col
  • Loading branch information
rikivillalba committed Dec 20, 2024
1 parent e275acf commit 3218515
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions R/bmerge.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ mergeType = function(x) {

cast_with_atts = function(x, as.f) {
ans = as.f(x)
# do not copy attributes when coercing factor (to character)
if (!is.factor(x) && !is.null(attributes(x))) attributes(ans) = attributes(x)
if (!is.null(attributes(x))) attributes(ans) = attributes(x)
ans
}

Expand All @@ -21,7 +20,9 @@ coerce_col = function(dt, col, from_type, to_type, from_name, to_name, from_deta
"Coercing %s column %s%s to type %s to match type of %s%s.\n",
from_type, from_name, from_detail, to_type, to_name, to_detail
)
set(dt, j=col, value=cast_with_atts(dt[[col]], match.fun(paste0("as.", to_type))))
as.f = switch(to_type, integer64 = bit64::as.integer64, match.fun(paste0("as.", to_type)))

Check warning on line 23 in R/bmerge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/bmerge.R,line=23,col=93,[trailing_whitespace_linter] Remove trailing whitespace.
# do not copy attributes when coercing factor (to character)
set(dt, j=col, value = if (is.factor(dt[[col]])) as.f(dt[[col]]) else cast_with_atts(dt[[col]], as.f))
}

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

0 comments on commit 3218515

Please sign in to comment.