You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# - do type coercions if necessary on just the shallow local copies for the purpose of join
51
51
# - handle factor columns appropriately
52
52
# Note that if i is keyed, if this coerces i's key gets dropped by set()
53
-
ic=icols[a]
54
-
xc=xcols[a]
55
-
x_merge_type= mergeType(x[[xc]])
56
-
i_merge_type= mergeType(i[[ic]])
57
-
xname= paste0("x.", names(x)[xc])
58
-
iname= paste0("i.", names(i)[ic])
53
+
icol=icols[a]
54
+
xcol=xcols[a]
55
+
x_merge_type= mergeType(x[[xcol]])
56
+
i_merge_type= mergeType(i[[icol]])
57
+
xname= paste0("x.", names(x)[xcol])
58
+
iname= paste0("i.", names(i)[icol])
59
59
if (!x_merge_type %chin% supported) stopf("%s is type %s which is not supported by data.table join", xname, x_merge_type)
60
60
if (!i_merge_type %chin% supported) stopf("%s is type %s which is not supported by data.table join", iname, i_merge_type)
61
61
if (x_merge_type=="factor"||i_merge_type=="factor") {
62
62
if (roll!=0.0&&a==length(icols))
63
63
stopf("Attempting roll join on factor column when joining %s to %s. Only integer, double or character columns may be roll joined.", xname, iname)
64
64
if (x_merge_type=="factor"&&i_merge_type=="factor") {
65
65
if (verbose) catf("Matching %s factor levels to %s factor levels.\n", iname, xname)
66
-
set(i, j=ic, value=chmatch(levels(i[[ic]]), levels(x[[xc]]), nomatch=0L)[i[[ic]]]) # nomatch=0L otherwise a level that is missing would match to NA values
66
+
set(i, j=icol, value=chmatch(levels(i[[icol]]), levels(x[[xcol]]), nomatch=0L)[i[[icol]]]) # nomatch=0L otherwise a level that is missing would match to NA values
67
67
next
68
68
} else {
69
69
if (x_merge_type=="character") {
70
70
if (verbose) catf("Coercing factor column %s to type character to match type of %s.\n", iname, xname)
71
-
set(i, j=ic, value=val<-as.character(i[[ic]]))
72
-
set(callersi, j=ic, value=val) # factor in i joining to character in x will return character and not keep x's factor; e.g. for antaresRead #3581
if (x_merge_type=="integer64"||i_merge_type=="integer64") {
102
102
nm= c(iname, xname)
103
-
if (x_merge_type=="integer64") { w=i; wc=ic; wclass=i_merge_type; } else { w=x; wc=xc; wclass=x_merge_type; nm=rev(nm) } # w is which to coerce
103
+
if (x_merge_type=="integer64") { w=i; wc=icol; wclass=i_merge_type; } else { w=x; wc=xcol; wclass=x_merge_type; nm=rev(nm) } # w is which to coerce
104
104
if (wclass=="integer"|| (wclass=="double"&&!isReallyReal(w[[wc]]))) {
105
105
if (verbose) catf("Coercing %s column %s%s to type integer64 to match type of %s.\n", wclass, nm[1L], if (wclass=="double") " (which contains no fractions)"else"", nm[2L])
106
106
set(w, j=wc, value=bit64::as.integer64(w[[wc]]))
107
107
} else stopf("Incompatible join types: %s is type integer64 but %s is type double and contains fractions", nm[2L], nm[1L])
108
108
} else {
109
109
# just integer and double left
110
-
ic_idx= which(ic==icols) # check if on is joined on multiple conditions
110
+
ic_idx= which(icol==icols) # check if on is joined on multiple conditions
111
111
if (i_merge_type=="double") {
112
112
coerce_x=FALSE
113
-
if (!isReallyReal(i[[ic]])) {
113
+
if (!isReallyReal(i[[icol]])) {
114
114
coerce_x=TRUE
115
115
# common case of ad hoc user-typed integers missing L postfix joining to correct integer keys
116
116
# we've always coerced to int and returned int, for convenience.
0 commit comments