diff --git a/NEWS.md b/NEWS.md index a2576e71d2..af8d5b0270 100644 --- a/NEWS.md +++ b/NEWS.md @@ -169,6 +169,8 @@ 9. `?"."`, `?".."`, `?".("`, and `?".()"` now point to `?data.table`, [#4385](https://github.com/Rdatatable/data.table/issues/4385) [#4407](https://github.com/Rdatatable/data.table/issues/4407). To help users find the documentation for these convenience features available inside `DT[...]`. Recall that `.` is an alias for `list`, and `..var` tells `data.table` to look for `var` in the calling environment as opposed to a column of the table. +10. `DT[, lhs:=rhs]` and `set(DT, , lhs, rhs)` no longer raise a warning on zero length `lhs`, [#4086](https://github.com/Rdatatable/data.table/issues/4086). Thanks to Jan Gorecki for the suggestion and PR. For example, `DT[, grep("foo", names(dt)) := NULL]` no longer warns if there are no column names containing `"foo"`. + # data.table [v1.14.0](https://github.com/Rdatatable/data.table/milestone/23?closed=1) (21 Feb 2021) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 79fee4fcd1..a934fec48a 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -5045,9 +5045,16 @@ if (test_bit64) { error="Cannot coerce 'list' RHS to 'integer64' to match.*column 6 named 'f'") } -# FR #343, when LHS evaluates to integer(0), provide warning and return dt, not an error. +# FR #343, when LHS evaluates to integer(0), provide warning and return dt, not an error... but then... #4086 set could allow empty input without warning dt = data.table(a = 1:5, b1 = 1:5, b2 = 1:5) -test(1295, dt[, grep("c", names(dt)) := NULL], dt, warning="length(LHS)==0; no columns to delete or assign RHS to") +test(1295.1, dt[, grep("c", names(dt)) := NULL], dt) +test(1295.2, set(dt, NULL, character(), 1L), dt) +test(1295.3, set(dt, 1L, character(), 1L), dt) +op = options(datatable.verbose=TRUE) +test(1295.4, dt[, grep("c", names(dt)) := NULL], dt, output="length(LHS)==0; no columns to delete or assign RHS to") +test(1295.5, set(dt, NULL, character(), 1L), dt, output="length(LHS)==0; no columns to delete or assign RHS to") +test(1295.6, set(dt, 1L, character(), 1L), dt, output="length(LHS)==0; no columns to delete or assign RHS to") +options(op) # Updating logical column in one-row DT (corruption of new R 3.1 internal globals for TRUE, FALSE and NA) DT = data.table(a=1:6, b=c(TRUE,FALSE)) diff --git a/src/assign.c b/src/assign.c index 1955fe502a..af3768f81a 100644 --- a/src/assign.c +++ b/src/assign.c @@ -352,7 +352,7 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values) } } if (!length(cols)) { - warning(_("length(LHS)==0; no columns to delete or assign RHS to.")); // test 1295 covers + if (verbose) Rprintf(_("length(LHS)==0; no columns to delete or assign RHS to.")); // test 1295 covers *_Last_updated = 0; UNPROTECT(protecti); return(dt);