Skip to content

Commit b07be17

Browse files
Allow tbl in i to use 'i.' and 'x.' prefixes in joins (#7025)
* allow x. and i. references to tbl in i * non-update-join test
1 parent b689cd2 commit b07be17

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
8. `fread()` no longer warns on certain systems on R 4.5.0+ where the file owner can't be resolved, [#6918](https://github.com/Rdatatable/data.table/issues/6918). Thanks @ProfFancyPants for the report and PR.
3838

39+
9. Joins to extended data.frames, e.g. `x[i, col := x.col1 + i.col2]` where `i` is a `tbl`, can use the `x.` and `i.` prefix forms, [#6998](https://github.com/Rdatatable/data.table/issues/6998). Thanks @MichaelChirico for the bug and PR.
40+
3941
### NOTES
4042

4143
1. Continued work to remove non-API C functions, [#6180](https://github.com/Rdatatable/data.table/issues/6180). Thanks Ivan Krylov for the PRs and for writing a clear and concise guide about the R API: https://aitap.codeberg.page/R-api/.

R/data.table.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,12 @@ replace_dot_alias = function(e) {
677677
}
678678
ansvals = chmatch(ansvars, nx)
679679
} else {
680-
if (is.data.table(i)) {
680+
if (is.data.frame(i)) {
681681
idotprefix = paste0("i.", names_i)
682682
xdotprefix = paste0("x.", names_x)
683-
} else idotprefix = xdotprefix = character(0L)
683+
} else {
684+
idotprefix = xdotprefix = character(0L)
685+
}
684686

685687
# j was substituted before dealing with i so that := can set allow.cartesian=FALSE (#800) (used above in i logic)
686688
if (is.null(jsub)) return(NULL)

inst/tests/tests.Rraw

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21140,3 +21140,20 @@ test(2316.1, between(tms[[1]], tms[[1L]], tms[[2L]]), error = "different tzone a
2114021140
test(2316.2, between(tms[[1]], tms[[1L]], tms[[2L]], ignore_tzone=TRUE))
2114121141
test(2316.3, between(tms[[1]], tms[[2L]], tms[[2L]]), message = "mismatched tzone attributes")
2114221142
test(2316.4, between(tms[[1]], tms[[2L]], tms[[2L]], ignore_tzone=TRUE))
21143+
21144+
# tbl in i still allows 'i.' prefix reference for update join, #6998
21145+
DT1 = data.table(a=1, b=2)
21146+
DT2 = data.table(a=1, c=3)
21147+
DF1 = data.frame(a=1, d=4)
21148+
DF2 = data.frame(a=1, e=5)
21149+
class(DF2) = c("tbl_df", "tbl", "data.frame")
21150+
21151+
test(2317.1, DT1[DT2, on='a', c := i.c]$c, 3)
21152+
test(2317.2, DT1[DT2, on='a', c2 := x.a + i.c]$c2, 4)
21153+
test(2317.3, DT1[DT2, on='a', .(c = x.a + i.c)]$c, 4)
21154+
test(2317.4, DT1[DF1, on='a', d := i.d]$d, 4)
21155+
test(2317.5, DT1[DF1, on='a', d2 := x.a + i.d]$d2, 5)
21156+
test(2317.6, DT1[DF1, on='a', .(d = x.a + i.d)]$d, 5)
21157+
test(2317.7, DT1[DF2, on='a', e := i.e]$e, 5)
21158+
test(2317.8, DT1[DF2, on='a', e2 := x.a + i.e]$e2, 6)
21159+
test(2317.9, DT1[DF2, on='a', .(e = x.a + i.e)]$e, 6)

0 commit comments

Comments
 (0)