Skip to content

Commit 56e3169

Browse files
rename: {i,x}c --> {i,x}col
I found myself wondering `ic`... "`i` character? `i` class?". Simpler to encode more info in the name
1 parent faa5474 commit 56e3169

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

R/bmerge.R

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,32 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
5050
# - do type coercions if necessary on just the shallow local copies for the purpose of join
5151
# - handle factor columns appropriately
5252
# 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])
5959
if (!x_merge_type %chin% supported) stopf("%s is type %s which is not supported by data.table join", xname, x_merge_type)
6060
if (!i_merge_type %chin% supported) stopf("%s is type %s which is not supported by data.table join", iname, i_merge_type)
6161
if (x_merge_type=="factor" || i_merge_type=="factor") {
6262
if (roll!=0.0 && a==length(icols))
6363
stopf("Attempting roll join on factor column when joining %s to %s. Only integer, double or character columns may be roll joined.", xname, iname)
6464
if (x_merge_type=="factor" && i_merge_type=="factor") {
6565
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
6767
next
6868
} else {
6969
if (x_merge_type=="character") {
7070
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
71+
set(i, j=icol, value=val<-as.character(i[[icol]]))
72+
set(callersi, j=icol, value=val) # factor in i joining to character in x will return character and not keep x's factor; e.g. for antaresRead #3581
7373
next
7474
} else if (i_merge_type=="character") {
7575
if (verbose) catf("Matching character column %s to factor levels in %s.\n", iname, xname)
76-
newvalue = chmatch(i[[ic]], levels(x[[xc]]), nomatch=0L)
77-
if (anyNA(i[[ic]])) newvalue[is.na(i[[ic]])] = NA_integer_ # NA_character_ should match to NA in factor, #3809
78-
set(i, j=ic, value=newvalue)
76+
newvalue = chmatch(i[[icol]], levels(x[[xcol]]), nomatch=0L)
77+
if (anyNA(i[[icol]])) newvalue[is.na(i[[icol]])] = NA_integer_ # NA_character_ should match to NA in factor, #3809
78+
set(i, j=icol, value=newvalue)
7979
next
8080
}
8181
}
@@ -88,29 +88,29 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
8888
cfl = c("character", "logical", "factor")
8989
if (x_merge_type %chin% cfl || i_merge_type %chin% cfl) {
9090
msg = gettext("Coercing all-NA %s column %s to type %s to match type of %s.\n")
91-
if (anyNA(i[[ic]]) && allNA(i[[ic]])) {
92-
coerce_col(i, ic, i_merge_type, x_merge_type, iname, xname, msg)
91+
if (anyNA(i[[icol]]) && allNA(i[[icol]])) {
92+
coerce_col(i, icol, i_merge_type, x_merge_type, iname, xname, msg)
9393
next
9494
}
95-
if (anyNA(x[[xc]]) && allNA(x[[xc]])) {
96-
coerce_col(x, xc, x_merge_type, i_merge_type, xname, iname, msg)
95+
if (anyNA(x[[xcol]]) && allNA(x[[xcol]])) {
96+
coerce_col(x, xcol, x_merge_type, i_merge_type, xname, iname, msg)
9797
next
9898
}
9999
stopf("Incompatible join types: %s (%s) and %s (%s)", xname, x_merge_type, iname, i_merge_type)
100100
}
101101
if (x_merge_type=="integer64" || i_merge_type=="integer64") {
102102
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
104104
if (wclass=="integer" || (wclass=="double" && !isReallyReal(w[[wc]]))) {
105105
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])
106106
set(w, j=wc, value=bit64::as.integer64(w[[wc]]))
107107
} else stopf("Incompatible join types: %s is type integer64 but %s is type double and contains fractions", nm[2L], nm[1L])
108108
} else {
109109
# 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
111111
if (i_merge_type=="double") {
112112
coerce_x = FALSE
113-
if (!isReallyReal(i[[ic]])) {
113+
if (!isReallyReal(i[[icol]])) {
114114
coerce_x = TRUE
115115
# common case of ad hoc user-typed integers missing L postfix joining to correct integer keys
116116
# we've always coerced to int and returned int, for convenience.
@@ -125,8 +125,8 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
125125
}
126126
if (coerce_x) {
127127
msg = gettext("Coercing %s column %s (which contains no fractions) to type %s to match type of %s.\n")
128-
coerce_col(i, ic, "double", "integer", iname, xname, msg)
129-
set(callersi, j=ic, value=i[[ic]]) # change the shallow copy of i up in [.data.table to reflect in the result, too.
128+
coerce_col(i, icol, "double", "integer", iname, xname, msg)
129+
set(callersi, j=icol, value=i[[icol]]) # change the shallow copy of i up in [.data.table to reflect in the result, too.
130130
if (length(ic_idx)>1L) {
131131
xc_idx = xcols[ic_idx]
132132
for (xb in xc_idx[which(vapply_1c(x[0L, xc_idx, with=FALSE], mergeType) == "double")]) {
@@ -137,11 +137,11 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
137137
}
138138
if (!coerce_x) {
139139
msg = gettext("Coercing %s column %s to type %s to match type of %s which contains fractions.\n")
140-
coerce_col(x, xc, "integer", "double", xname, iname, msg)
140+
coerce_col(x, xcol, "integer", "double", xname, iname, msg)
141141
}
142142
} else {
143143
msg = gettext("Coercing %s column %s to type %s for join to match type of %s.\n")
144-
coerce_col(i, ic, "integer", "double", iname, xname, msg)
144+
coerce_col(i, icol, "integer", "double", iname, xname, msg)
145145
if (length(ic_idx)>1L) {
146146
xc_idx = xcols[ic_idx]
147147
for (xb in xc_idx[which(vapply_1c(x[0L, xc_idx, with=FALSE], mergeType) == "integer")]) {

0 commit comments

Comments
 (0)