Skip to content

Commit de0cfb4

Browse files
allow x. and i. references to tbl in i
1 parent 5f4258e commit de0cfb4

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

NEWS.md

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

3535
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.
3636

37+
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.
38+
3739
### NOTES
3840

3941
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21133,3 +21133,17 @@ test(2315.1, tail(DT[order(i), i], 2L), 1:2)
2113321133
# wider range of numbers needed for further coverage
2113421134
DT[1L, i := 1000L]
2113521135
test(2315.2, tail(DT[order(i), i], 2L), c(1L, 1000L))
21136+
21137+
# tbl in i still allows 'i.' prefix reference for update join, #6998
21138+
DT1 = data.table(a=1, b=2)
21139+
DT2 = data.table(a=1, c=3)
21140+
DF1 = data.frame(a=1, d=4)
21141+
DF2 = data.frame(a=1, e=5)
21142+
class(DF2) = c("tbl_df", "tbl", "data.frame")
21143+
21144+
test(2316.1, DT1[DT2, on='a', c := i.c]$c, 3)
21145+
test(2316.2, DT1[DT2, on='a', c2 := x.a + i.c]$c2, 4)
21146+
test(2316.3, DT1[DF1, on='a', d := i.d]$d, 4)
21147+
test(2316.4, DT1[DF1, on='a', d2 := x.a + i.d]$d2, 5)
21148+
test(2316.5, DT1[DF2, on='a', e := i.e]$e, 5)
21149+
test(2316.6, DT1[DF2, on='a', e2 := x.a + i.e]$e2, 6)

0 commit comments

Comments
 (0)