Skip to content

Commit ff934cc

Browse files
committed
rename x/i class
1 parent 1d7a8c2 commit ff934cc

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

R/bmerge.R

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,70 +41,70 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
4141
# Note that if i is keyed, if this coerces i's key gets dropped by set()
4242
ic = icols[a]
4343
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]])
4646
xname = paste0("x.", names(x)[xc])
4747
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") {
5151
if (roll!=0.0 && a==length(icols))
5252
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") {
5454
if (verbose) catf("Matching %s factor levels to %s factor levels.\n", iname, xname)
5555
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
5656
next
5757
} else {
58-
if (xclass=="character") {
58+
if (x_merge_type=="character") {
5959
if (verbose) catf("Coercing factor column %s to type character to match type of %s.\n", iname, xname)
6060
set(i, j=ic, value=val<-as.character(i[[ic]]))
6161
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
6262
next
63-
} else if (iclass=="character") {
63+
} else if (i_merge_type=="character") {
6464
if (verbose) catf("Matching character column %s to factor levels in %s.\n", iname, xname)
6565
newvalue = chmatch(i[[ic]], levels(x[[xc]]), nomatch=0L)
6666
if (anyNA(i[[ic]])) newvalue[is.na(i[[ic]])] = NA_integer_ # NA_character_ should match to NA in factor, #3809
6767
set(i, j=ic, value=newvalue)
6868
next
6969
}
7070
}
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)
7272
}
73-
if (xclass == iclass) {
73+
if (x_merge_type == i_merge_type) {
7474
if (length(icols)>1 && is(x[[xc]], "Date") && is(i[[ic]], "Date")) {
7575
set(x, j=xc, value=as.double(x[[xc]]))
7676
set(i, j=ic, value=as.double(i[[ic]]))
7777
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)
7878
} 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)
8080
}
8181
next
8282
}
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" ||
84+
x_merge_type=="logical" || i_merge_type=="logical" ||
85+
x_merge_type=="factor" || i_merge_type=="factor") {
8686
if (anyNA(i[[ic]]) && allNA(i[[ic]])) {
87-
if (verbose) catf("Coercing all-NA %s (%s) to type %s to match type of %s.\n", iname, iclass, xclass, xname)
88-
set(i, j=ic, value=match.fun(paste0("as.", xclass))(i[[ic]]))
87+
if (verbose) catf("Coercing all-NA %s (%s) to type %s to match type of %s.\n", iname, i_merge_type, x_merge_type, xname)
88+
set(i, j=ic, value=match.fun(paste0("as.", x_merge_type))(i[[ic]]))
8989
next
9090
}
9191
else if (anyNA(x[[xc]]) && allNA(x[[xc]])) {
92-
if (verbose) catf("Coercing all-NA %s (%s) to type %s to match type of %s.\n", xname, xclass, iclass, iname)
93-
set(x, j=xc, value=match.fun(paste0("as.", iclass))(x[[xc]]))
92+
if (verbose) catf("Coercing all-NA %s (%s) to type %s to match type of %s.\n", xname, x_merge_type, i_merge_type, iname)
93+
set(x, j=xc, value=match.fun(paste0("as.", i_merge_type))(x[[xc]]))
9494
next
9595
}
96-
stopf("Incompatible join types: %s (%s) and %s (%s)", xname, xclass, iname, iclass)
96+
stopf("Incompatible join types: %s (%s) and %s (%s)", xname, x_merge_type, iname, i_merge_type)
9797
}
98-
if (xclass=="integer64" || iclass=="integer64") {
98+
if (x_merge_type=="integer64" || i_merge_type=="integer64") {
9999
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
101101
if (wclass=="integer" || (wclass=="double" && !isReallyReal(w[[wc]]))) {
102102
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])
103103
set(w, j=wc, value=bit64::as.integer64(w[[wc]]))
104104
} else stopf("Incompatible join types: %s is type integer64 but %s is type double and contains fractions", nm[2L], nm[1L])
105105
} else {
106106
# just integer and double left
107-
if (iclass=="double") {
107+
if (i_merge_type=="double") {
108108
if (!isReallyReal(i[[ic]])) {
109109
# common case of ad hoc user-typed integers missing L postfix joining to correct integer keys
110110
# we've always coerced to int and returned int, for convenience.

0 commit comments

Comments
 (0)