Skip to content

Commit 1aaca4c

Browse files
Progress deprecation of with=FALSE + :=
1 parent 436bd6c commit 1aaca4c

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ rowwiseDT(
137137

138138
6. `measurev()` was implemented and documented in v1.15.0, for use within `melt()`, and it is now exported (dependent packages can now use without a NOTE from CRAN check).
139139

140+
7. Deprecation of `:=` and `with=FALSE` has been upgraded from warning (since v1.15.0) to error. Long ago (before 2014), this was needed when, e.g., assigning to a vector of column names defined outside the table, but `with=FALSE` is no longer needed to do so: `DT[, (cols) := ...]` works fine.
141+
140142
# data.table [v1.16.2](https://github.com/Rdatatable/data.table/milestone/35) (9 October 2024)
141143

142144
## BUG FIXES

R/data.table.R

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -685,19 +685,11 @@ replace_dot_alias = function(e) {
685685
# j was substituted before dealing with i so that := can set allow.cartesian=FALSE (#800) (used above in i logic)
686686
if (is.null(jsub)) return(NULL)
687687

688-
if (!with && jsub %iscall% ":=") {
689-
# TODO: make these both errors (or single long error in both cases) in next release.
690-
# i.e. using with=FALSE together with := at all will become an error. Eventually with will be removed.
691-
if (is.null(names(jsub)) && is.name(jsub[[2L]])) {
692-
warningf("with=FALSE together with := was deprecated in v1.9.4 released Oct 2014. Please wrap the LHS of := with parentheses; e.g., DT[,(myVar):=sum(b),by=a] to assign to column name(s) held in variable myVar. See ?':=' for other examples. As warned in 2014, this is now a warning.")
693-
jsub[[2L]] = eval(jsub[[2L]], parent.frame(), parent.frame())
694-
} else {
695-
warningf("with=FALSE ignored, it isn't needed when using :=. See ?':=' for examples.")
696-
}
697-
with = TRUE
698-
}
699-
700688
if (!with) {
689+
if (jsub %iscall% ":=") {
690+
# TODO(>=1.18.0): Simplify this error
691+
stopf("with=FALSE together with := was deprecated in v1.9.4 released Oct 2014; this has been warning since v1.15.0. Please wrap the LHS of := with parentheses; e.g., DT[,(myVar):=sum(b),by=a] to assign to column name(s) held in variable myVar. See ?':=' for other examples.")
692+
}
701693
# missingby was already checked above before dealing with i
702694
if (jsub %iscall% c("!", "-") && length(jsub)==2L) { # length 2 to only match unary, #2109
703695
notj = TRUE

inst/tests/tests.Rraw

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4658,7 +4658,7 @@ test(1241, DT[order(x,-y)], # optimized to forder()
46584658

46594659
DT = data.table(a=1:3, b=4:6)
46604660
myCol = "a"
4661-
test(1242.1, DT[2,myCol:=6L,with=FALSE], data.table(a=INT(1,6,3), b=4:6), warning="with=FALSE together with := was deprecated in v1.9.4 released Oct 2014. Please")
4661+
test(1242.1, DT[2,myCol:=6L,with=FALSE], error="with=FALSE together with := was deprecated in v1.9.4)
46624662
test(1242.2, DT[2,(myCol):=7L], data.table(a=INT(1,7,3), b=4:6))
46634663

46644664
# consistency of output type of mult, #340
@@ -13935,8 +13935,7 @@ test(1967.42, x[3, rollends = rep(TRUE, 10L)], error = 'rollends must be length
1393513935
test(1967.43, x[ , ..], error = 'symbol .. is invalid')
1393613936
test(1967.44, x[NULL], data.table(NULL))
1393713937
test(1967.45, x[ , NULL], NULL)
13938-
test(1967.46, x[ , 'b' := 6:10, with = FALSE],
13939-
data.table(a = 1:5, b = 6:10), warning = 'with=FALSE ignored')
13938+
test(1967.46, x[ , 'b' := 6:10, with=FALSE], error='with=FALSE ignored')
1394013939
test(1967.47, x[ , -1L, with = FALSE], data.table(b = 6:10))
1394113940
test(1967.48, x[ , b, .SDcols = 'a'], 6:10,
1394213941
warning = "This j doesn't use .SD")

0 commit comments

Comments
 (0)