Skip to content

Commit 44eaa7f

Browse files
committed
add tests and fix
1 parent 738779b commit 44eaa7f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

R/data.table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ replace_dot_alias = function(e) {
14481448
if (SD_only)
14491449
jvnames = jnames = sdvars
14501450
else
1451-
jnames = as.character(Filter(is.name, jsub)[-1L])
1451+
jnames = vapply_1c(jsub, \(x) `if`(is.name(x), as.character(x), NA_character_))[-1L]
14521452
key_idx = chmatch(key, jnames)
14531453
missing_keys = which(is.na(key_idx))
14541454
if (length(missing_keys) && missing_keys[1L] == 1L) return(NULL)

inst/tests/tests.Rraw

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21837,3 +21837,29 @@ DT[, V1000 := 20:1]
2183721837
test(2343.1, forderv(DT, by=names(DT), sort=FALSE, retGrp=TRUE), forderv(DT, by=c("V1", "V1000"), sort=FALSE, retGrp=TRUE))
2183821838
x = c(rep(0, 7e5), 1e6)
2183921839
test(2343.2, forderv(list(x)), integer(0))
21840+
21841+
# Keep key when new column added before existing key in j
21842+
# Incorrect key can lead to incorrect join result #7364
21843+
local({
21844+
test(2344.00, key(data.table(V1 = 1:2, key = "V1")[, .(V2 = c("b", "a"), V1)]), "V1")
21845+
test(2344.01, key(data.table(V1 = 1:2, key = "V1")[, .(V2 = -V1, V1)]), "V1")
21846+
21847+
d1 = data.table(
21848+
V1 = c(1L, 0L, 1L),
21849+
V2 = c("a", "a", "b"),
21850+
key = "V2"
21851+
)
21852+
21853+
d2 = d1[, .(
21854+
V1,
21855+
label = c("one", "zero", "one"),
21856+
V2
21857+
)]
21858+
21859+
r = d2[
21860+
data.table(label = "one"),
21861+
on = "label",
21862+
allow.cartesian = TRUE
21863+
]
21864+
test(2344.02, nrow(r), 2L)
21865+
})

0 commit comments

Comments
 (0)