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
# Note that if i is keyed, if this coerces i's key gets dropped by set()
42
42
ic=icols[a]
43
43
xc=xcols[a]
44
-
xclass= getClass(x[[xc]])
45
-
iclass= getClass(i[[ic]])
44
+
x_merge_type= getClass(x[[xc]])
45
+
i_merge_type= getClass(i[[ic]])
46
46
xname= paste0("x.", names(x)[xc])
47
47
iname= paste0("i.", names(i)[ic])
48
-
if (!xclass %chin% supported) stopf("%s is type %s which is not supported by data.table join", xname, xclass)
49
-
if (!iclass %chin% supported) stopf("%s is type %s which is not supported by data.table join", iname, iclass)
50
-
if (xclass=="factor"||iclass=="factor") {
48
+
if (!x_merge_type %chin% supported) stopf("%s is type %s which is not supported by data.table join", xname, x_merge_type)
49
+
if (!i_merge_type %chin% supported) stopf("%s is type %s which is not supported by data.table join", iname, i_merge_type)
50
+
if (x_merge_type=="factor"||i_merge_type=="factor") {
51
51
if (roll!=0.0&&a==length(icols))
52
52
stopf("Attempting roll join on factor column when joining %s to %s. Only integer, double or character columns may be roll joined.", xname, iname)
53
-
if (xclass=="factor"&&iclass=="factor") {
53
+
if (x_merge_type=="factor"&&i_merge_type=="factor") {
54
54
if (verbose) catf("Matching %s factor levels to %s factor levels.\n", iname, xname)
55
55
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
56
56
next
57
57
} else {
58
-
if (xclass=="character") {
58
+
if (x_merge_type=="character") {
59
59
if (verbose) catf("Coercing factor column %s to type character to match type of %s.\n", iname, xname)
60
60
set(i, j=ic, value=val<-as.character(i[[ic]]))
61
61
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
62
62
next
63
-
} elseif (iclass=="character") {
63
+
} elseif (i_merge_type=="character") {
64
64
if (verbose) catf("Matching character column %s to factor levels in %s.\n", iname, xname)
if (anyNA(i[[ic]])) newvalue[is.na(i[[ic]])] =NA_integer_# NA_character_ should match to NA in factor, #3809
67
67
set(i, j=ic, value=newvalue)
68
68
next
69
69
}
70
70
}
71
-
stopf("Incompatible join types: %s (%s) and %s (%s). Factor columns must join to factor or character columns.", xname, xclass, iname, iclass)
71
+
stopf("Incompatible join types: %s (%s) and %s (%s). Factor columns must join to factor or character columns.", xname, x_merge_type, iname, i_merge_type)
72
72
}
73
-
if (xclass==iclass) {
73
+
if (x_merge_type==i_merge_type) {
74
74
if (length(icols)>1&& is(x[[xc]], "Date") && is(i[[ic]], "Date")) {
75
75
set(x, j=xc, value=as.double(x[[xc]]))
76
76
set(i, j=ic, value=as.double(i[[ic]]))
77
77
if (verbose) catf("%s and %s are both Dates. R does not guarentee a type for Date internally, hence, coercing to double.\n", iname, xname)
78
78
} else {
79
-
if (verbose) catf("%s has same type (%s) as %s. No coercion needed.\n", iname, xclass, xname)
79
+
if (verbose) catf("%s has same type (%s) as %s. No coercion needed.\n", iname, x_merge_type, xname)
80
80
}
81
81
next
82
82
}
83
-
if (xclass=="character"||iclass=="character"||
84
-
xclass=="logical"||iclass=="logical"||
85
-
xclass=="factor"||iclass=="factor") {
83
+
if (x_merge_type=="character"||i_merge_type=="character"||
if (x_merge_type=="integer64"||i_merge_type=="integer64") {
99
99
nm= c(iname, xname)
100
-
if (xclass=="integer64") { w=i; wc=ic; wclass=iclass; } else { w=x; wc=xc; wclass=xclass; nm=rev(nm) } # w is which to coerce
100
+
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
101
101
if (wclass=="integer"|| (wclass=="double"&&!isReallyReal(w[[wc]]))) {
102
102
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])
103
103
set(w, j=wc, value=bit64::as.integer64(w[[wc]]))
104
104
} else stopf("Incompatible join types: %s is type integer64 but %s is type double and contains fractions", nm[2L], nm[1L])
105
105
} else {
106
106
# just integer and double left
107
-
if (iclass=="double") {
107
+
if (i_merge_type=="double") {
108
108
if (!isReallyReal(i[[ic]])) {
109
109
# common case of ad hoc user-typed integers missing L postfix joining to correct integer keys
110
110
# we've always coerced to int and returned int, for convenience.
0 commit comments