Skip to content

Commit

Permalink
Allow .SD; allow original is.sorted portion to escape if irows is.null
Browse files Browse the repository at this point in the history
  • Loading branch information
ColeMiller1 authored May 28, 2020
1 parent d1662b3 commit 21e68c0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -1337,21 +1337,21 @@ replace_dot_alias = function(e) {
if (is.data.table(jval)) {
setattr(jval, 'class', class(x)) # fix for #64
# can jval be sorted by the same key as x? improved for #4498
get_shared_keys = function(jsub, jvnames, key) {
get_shared_keys = function(jsub, jvnames, sdvars, key) {
if (is.null(key)) return(NULL)
if (!jsub %iscall% "list") return(NULL)
jnames = as.character(Filter(is.name, jsub)[-1L])
if (!((SD_only <- jsub == quote(.SD))|| jsub %iscall% "list")) return(NULL)
jnames = if (SD_only) sdvars else as.character(Filter(is.name, jsub)[-1L])
key_idx = chmatch(key, jnames)
missing_keys = which(is.na(key_idx))
if (length(missing_keys) && missing_keys[1L] == 1L) return(NULL)
if (!length(missing_keys)) return(jvnames[key_idx])
return(jvnames[head(key_idx, missing_keys[1L] - 1L)])
}
shared_keys = get_shared_keys(jsub, jvnames, key(x))
shared_keys = get_shared_keys(jsub, jvnames, sdvars = sdvars, key(x))
if (is.null(irows) && !is.null(shared_keys)) {
setattr(jval, 'sorted', shared_keys)
# potentially inefficient backup -- check if jval is sorted by key(x)
} else if (haskey(x) && all(key(x) %chin% names(jval)) && suppressWarnings(is.sorted(jval, by=key(x)))) { # TO DO: perhaps this usage of is.sorted should be allowed internally then (tidy up and make efficient)
} else if (haskey(x) && all(key(x) %chin% names(jval)) && (is.null(irows) || (!roll && .Call(CisOrderedSubset, irows, nrow(x))) || suppressWarnings(is.sorted(jval, by=key(x))))) { # TO DO: perhaps this usage of is.sorted should be allowed internally then (tidy up and make efficient)
setattr(jval, 'sorted', key(x))
}
if (any(vapply_1b(jval, is.null))) stop("Internal error: j has created a data.table result containing a NULL column") # nocov
Expand Down

0 comments on commit 21e68c0

Please sign in to comment.