From 009859e99d18984fff5360ffbd35d75aaf5fd9e9 Mon Sep 17 00:00:00 2001 From: jangorecki Date: Thu, 2 Apr 2020 12:53:56 +0100 Subject: [PATCH] set for empty cols does not warn anymore, #4086 --- NEWS.md | 2 ++ inst/tests/tests.Rraw | 11 +++++++++-- src/assign.c | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 71fd76aa65..833cb8fecf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -145,6 +145,8 @@ unit = "s") 7. Added more explanation/examples to `?data.table` for how to use `.BY`, [#1363](https://github.com/Rdatatable/data.table/issues/1363). +8. When attempting to add, modify or delete a column with `DT[, lhs := rhs]` or `set(DT, , lhs, rhs)` a zero length `lhs` object will no longer raise a warning, [#4086](https://github.com/Rdatatable/data.table/issues/4086). + # data.table [v1.12.8](https://github.com/Rdatatable/data.table/milestone/15?closed=1) (09 Dec 2019) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 7cc6819e8f..74dca10250 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -4950,9 +4950,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 1392079e72..1c521d72f0 100644 --- a/src/assign.c +++ b/src/assign.c @@ -342,7 +342,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);