Skip to content

Commit

Permalink
Handled case when no secondary indices are set, #1479
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Mar 9, 2016
1 parent 6d751f6 commit fa9dca0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -1720,9 +1720,11 @@ chmatch2 <- function(x, table, nomatch=NA_integer_) {
# fixes #1479. Take care of secondary indices, TODO: cleaner way of doing this
attrs = attr(x, 'index')
skeys = names(attributes(attrs))
hits = unlist(lapply(paste("__", names(x)[cols], sep=""), function(x) grep(x, skeys)))
hits = skeys[unique(hits)]
for (i in seq_along(hits)) setattr(attrs, hits[i], NULL) # does by reference
if (!is.null(skeys)) {
hits = unlist(lapply(paste("__", names(x)[cols], sep=""), function(x) grep(x, skeys)))
hits = skeys[unique(hits)]
for (i in seq_along(hits)) setattr(attrs, hits[i], NULL) # does by reference
}
if (!missing(keyby)) {
cnames = as.character(bysubl)[-1]
if (all(cnames %chin% names(x)))
Expand Down
2 changes: 2 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -7887,6 +7887,8 @@ dt = data.table(a = rep(c(F,F,T,F,F,F,F,F,F), 3), b = c("x", "y", "z"))
set2key(dt, b)
dt[, a := as.logical(sum(a)), by = b]
test(1632.2, names(attributes(attr(dt, 'index'))), "__b")
dt = data.table(a = rep(c(F,F,T,F,F,F,F,F,F), 3), b = c("x", "y", "z"))
test(1632.3, copy(dt)[, c := !a, by=b], copy(dt)[, c := c(T,T,F,T,T,T,T,T,T)])

##########################

Expand Down

0 comments on commit fa9dca0

Please sign in to comment.