@@ -9,20 +9,20 @@ mergeType = function(x) {
99 ans
1010}
1111
12- cast_with_atts = function (x , as.f ) {
13- ans = as.f(x )
14- if (! is.null(attributes(x ))) attributes(ans ) = attributes(x )
12+ cast_with_attrs = function (x , cast_fun ) {
13+ ans = cast_fun(x )
14+ # do not copy attributes when coercing factor (to character)
15+ if (! is.factor(x ) && ! is.null(attributes(x ))) attributes(ans ) = attributes(x )
1516 ans
1617}
1718
18- coerce_col = function (dt , col , from_type , to_type , from_name , to_name , from_detail = " " , to_detail = " " , verbose ) {
19+ coerce_col = function (dt , col , from_type , to_type , from_name , to_name , from_detail = " " , to_detail = " " , verbose ) {
1920 if (verbose ) catf(
2021 " Coercing %s column %s%s to type %s to match type of %s%s.\n " ,
2122 from_type , from_name , from_detail , to_type , to_name , to_detail
2223 )
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 ))
24+ cast_fun = switch (to_type , integer64 = bit64 :: as.integer64 , match.fun(paste0(" as." , to_type )))
25+ set(dt , j = col , value = cast_with_attrs(dt [[col ]], cast_fun ))
2626}
2727
2828bmerge = function (i , x , icols , xcols , roll , rollends , nomatch , mult , ops , verbose )
0 commit comments