Skip to content

Commit a39bf17

Browse files
simplify making out.{x,i}
1 parent ec0173d commit a39bf17

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

R/mergelist.R

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,24 @@ mergepair = function(lhs, rhs, on, how, mult, lhs.cols=names(lhs), rhs.cols=name
183183
## binary merge
184184
ans = dtmerge(x=join_to, i=join_from, on=on, how=how, mult=mult, verbose=verbose, join.many=join.many)
185185

186-
## make i side
187-
out.i = if (is.null(ans$irows))
188-
.shallow(join_from, cols=someCols(join_from, from_cols, keep=on, retain.order=semi_or_anti), retain.key=TRUE)
189-
else
190-
.Call(CsubsetDT, join_from, ans$irows, someCols(join_from, from_cols, keep=on, retain.order=semi_or_anti))
191-
copy_i = copy_i || !is.null(ans$irows)
186+
## make i side; avoid subsetting if possible
187+
cols_i = someCols(join_from, from_cols, keep=on, retain.order=semi_or_anti)
188+
if (is.null(ans$irows)) {
189+
out.i = .shallow(join_from, cols=cols_i, retain.key=TRUE)
190+
} else {
191+
out.i = .Call(CsubsetDT, join_from, ans$irows, cols_i)
192+
copy_i = TRUE
193+
}
192194

193195
## make x side
196+
copy_x = TRUE
194197
if (semi_or_anti) {
195-
out.x = list(); copy_x = TRUE
198+
out.x = list()
196199
} else {
197-
out.x = if (is.null(ans$xrows)) ## as of now xrows cannot be NULL #4409 thus nocov below
198-
internal_error("dtmerge()$xrows returned NULL, #4409 been resolved but related code has not been updated?") #.shallow(join_to, cols=someCols(join_to, to_cols, drop=on), retain.key=TRUE) # nocov ## as of now nocov does not make difference r-lib/covr#279
199-
else
200-
.Call(CsubsetDT, join_to, ans$xrows, someCols(join_to, to_cols, drop=on))
201-
copy_x = !is.null(ans$xrows)
200+
if (is.null(ans$xrows)) ## as of now xrows cannot be NULL #4409 thus nocov below
201+
internal_error("dtmerge()$xrows returned NULL, #4409 been resolved but related code has not been updated?") # nocov
202+
out.x = .Call(CsubsetDT, join_to, ans$xrows, someCols(join_to, to_cols, drop=on))
203+
copy_x = TRUE
202204
## ensure no duplicated column names in merge results
203205
if (any(dup.i <- names(out.i) %chin% names(out.x)))
204206
stopf("merge result has duplicated column names, use 'cols' argument or rename columns in 'l' tables, duplicated column(s): %s", brackify(names(out.i)[dup.i]))

0 commit comments

Comments
 (0)