Skip to content

Commit b150ab5

Browse files
Retain with=FALSE in j=lit:var cases (#6700)
1 parent bfd62e5 commit b150ab5

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ rowwiseDT(
9595
# [1] "V1" "b" "c"
9696
```
9797

98-
4. Queries like `DT[, min(x):max(x)]` now work as expected, i.e. the same as `DT[, seq(min(x), max(x))]` or `with(DT, min(x):max(x))`, [#2069](https://github.com/Rdatatable/data.table/issues/2069). Shorthand like `DT[, a:b]` meaning "select from columns `a` through `b`" still works. Thanks to @franknarf1 for reporting, @jangorecki for the fix, and @MichaelChirico for a follow-up ensuring back-compatibility.
98+
4. Queries like `DT[, min(x):max(x)]` now work as expected, i.e. the same as `DT[, seq(min(x), max(x))]` or `with(DT, min(x):max(x))`, [#2069](https://github.com/Rdatatable/data.table/issues/2069). Shorthand like `DT[, a:b]` meaning "select from columns `a` through `b`" still works. Thanks to @franknarf1 for reporting, @jangorecki for the fix, and @MichaelChirico for follow-ups ensuring back-compatibility.
9999

100100
5. `fread()` performance improves when specifying `Date` among `colClasses`, [#6105](https://github.com/Rdatatable/data.table/issues/6105). One implication of the change is that the column will be an `IDate` (which also inherits from `Date`), which may affect code strongly relying on the column class to be `Date` exactly; computations with `IDate` and `Date` columns should otherwise be the same. If you strongly prefer the `Date` class, run `as.Date()` explicitly following `fread()`. Thanks @scipima for the report and @MichaelChirico for the fix.
101101

R/data.table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3045,7 +3045,7 @@ rleidv = function(x, cols=seq_along(x), prefix=NULL) {
30453045
if (root != ":") return(FALSE)
30463046
if (!length(vars)) return(TRUE) # e.g. 1:10
30473047
if (!all(vars %chin% names(x))) return(TRUE) # e.g. 1:ncol(x)
3048-
is.name(e[[1L]]) && is.name(e[[2L]]) # e.g. V1:V2, but not min(V1):max(V2) or 1:max(V2)
3048+
!is.call(e[[2L]]) && !is.call(e[[3L]]) # e.g. V1:V2, but not min(V1):max(V2) or 1:max(V2)
30493049
}
30503050

30513051
# GForce functions

inst/tests/tests.Rraw

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19219,16 +19219,29 @@ for (opt in c(0, 1, 2)) {
1921919219

1922019220
# Confusing behavior with DT[, min(var):max(var)] #2069
1922119221
DT = data.table(t = c(2L, 1L, 3L), a=0, b=1)
19222-
test(2284.1, DT[, min(t):max(t)], with(DT, min(t):max(t)))
19223-
test(2284.2, DT[, 1:max(t)], with(DT, 1:max(t)))
19224-
test(2284.3, DT[, max(t):1], with(DT, max(t):1))
19225-
test(2284.4, DT[, 1:t[1L]], with(DT, 1:t[1L]))
19226-
test(2284.5, DT[, t[2L]:1], with(DT, t[2L]:1))
19227-
test(2284.6, DT[, min(a):max(t)], with(DT, min(a):max(t)))
19222+
test(2284.01, DT[, min(t):max(t)], with(DT, min(t):max(t)))
19223+
test(2284.02, DT[, 1:max(t)], with(DT, 1:max(t)))
19224+
test(2284.03, DT[, max(t):1], with(DT, max(t):1))
19225+
test(2284.04, DT[, 1:t[1L]], with(DT, 1:t[1L]))
19226+
test(2284.05, DT[, t[2L]:1], with(DT, t[2L]:1))
19227+
test(2284.06, DT[, min(a):max(t)], with(DT, min(a):max(t)))
1922819228
# but not every `:` with a call in from or to is with=TRUE, #6486
19229-
test(2284.7, DT[, 1:ncol(DT)], DT)
19230-
test(2284.8, DT[, 2:(ncol(DT) - 1L)], DT[, "a"])
19231-
test(2284.9, DT[, (ncol(DT) - 1L):ncol(DT)], DT[, c("a", "b")])
19229+
test(2284.07, DT[, 1:ncol(DT)], DT)
19230+
test(2284.08, DT[, 2:(ncol(DT) - 1L)], DT[, "a"])
19231+
test(2284.09, DT[, (ncol(DT) - 1L):ncol(DT)], DT[, c("a", "b")])
19232+
# literal:var is the same as literal:literal and var:var
19233+
test(2284.10, DT[, 1:a], DT[, t:a])
19234+
test(2284.11, DT[, 1:a], DT[, 1:2])
19235+
test(2284.12, DT[, t:2], DT[, t:a])
19236+
test(2284.13, DT[, t:2], DT[, 1:2])
19237+
test(2284.14, DT[, 1:b], DT[, t:b])
19238+
test(2284.15, DT[, 1:b], DT[, 1:3])
19239+
test(2284.16, DT[, t:3], DT[, t:b])
19240+
test(2284.17, DT[, t:3], DT[, 1:3])
19241+
test(2284.18, DT[, 2:b], DT[, a:b])
19242+
test(2284.19, DT[, 2:b], DT[, 2:3])
19243+
test(2284.20, DT[, a:3], DT[, a:b])
19244+
test(2284.21, DT[, a:3], DT[, 2:3])
1923219245

1923319246
# Extra regression tests for #4772, which was already incidentally fixed by #5183.
1923419247
x = data.table(a=1:3)

0 commit comments

Comments
 (0)