diff --git a/NEWS.md b/NEWS.md index 885eb56c5..b9927d73d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -137,6 +137,8 @@ rowwiseDT( 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). +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. + # data.table [v1.16.2](https://github.com/Rdatatable/data.table/milestone/35) (9 October 2024) ## BUG FIXES diff --git a/R/data.table.R b/R/data.table.R index 6594cb928..5b1437a3a 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -685,19 +685,11 @@ replace_dot_alias = function(e) { # j was substituted before dealing with i so that := can set allow.cartesian=FALSE (#800) (used above in i logic) if (is.null(jsub)) return(NULL) - if (!with && jsub %iscall% ":=") { - # TODO: make these both errors (or single long error in both cases) in next release. - # i.e. using with=FALSE together with := at all will become an error. Eventually with will be removed. - if (is.null(names(jsub)) && is.name(jsub[[2L]])) { - 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.") - jsub[[2L]] = eval(jsub[[2L]], parent.frame(), parent.frame()) - } else { - warningf("with=FALSE ignored, it isn't needed when using :=. See ?':=' for examples.") - } - with = TRUE - } - if (!with) { + if (jsub %iscall% ":=") { + # TODO(>=1.18.0): Simplify this error + 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.") + } # missingby was already checked above before dealing with i if (jsub %iscall% c("!", "-") && length(jsub)==2L) { # length 2 to only match unary, #2109 notj = TRUE diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 657478c61..0f6a8139d 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -4658,7 +4658,7 @@ test(1241, DT[order(x,-y)], # optimized to forder() DT = data.table(a=1:3, b=4:6) myCol = "a" -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") +test(1242.1, DT[2,myCol:=6L,with=FALSE], error="with=FALSE together with := was deprecated in v1.9.4) test(1242.2, DT[2,(myCol):=7L], data.table(a=INT(1,7,3), b=4:6)) # 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 test(1967.43, x[ , ..], error = 'symbol .. is invalid') test(1967.44, x[NULL], data.table(NULL)) test(1967.45, x[ , NULL], NULL) -test(1967.46, x[ , 'b' := 6:10, with = FALSE], - data.table(a = 1:5, b = 6:10), warning = 'with=FALSE ignored') +test(1967.46, x[ , 'b' := 6:10, with=FALSE], error='with=FALSE ignored') test(1967.47, x[ , -1L, with = FALSE], data.table(b = 6:10)) test(1967.48, x[ , b, .SDcols = 'a'], 6:10, warning = "This j doesn't use .SD")