From 00284c6858c4e2196df09cc3a9add93bf7e28224 Mon Sep 17 00:00:00 2001 From: mattdowle Date: Fri, 25 Jul 2014 23:24:23 +0200 Subject: [PATCH] :=NULL together with i is now an error --- README.md | 2 ++ inst/tests/tests.Rraw | 5 +++++ src/assign.c | 1 + 3 files changed, 8 insertions(+) diff --git a/README.md b/README.md index aefb9f88d..84c1678ec 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,8 @@ We moved from R-Forge to GitHub on 9 June 2014, including history. DT[,.(colB,colC,colD)] # same ``` Similarly, `by=.()` is now a shortcut for `by=list()`, for consistency with `i` and `j`. + + 28. `DT[where, someCol:=NULL]` is now an error that i is provided since it makes no sense to delete a column for only a subset of rows. diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index f81d90093..35d20097b 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -4900,10 +4900,15 @@ test(1352.6, DT[,sum(b),by=.(a%%2)], DT[,sum(b),by=a%%2]) test(1352.7, DT[,sum(b),by=.(Grp=a%%2)], DT[,sum(b),by=list(Grp=a%%2)]) test(1352.8, DT[,sum(b),by=.(a%%2,c)], DT[,sum(b),by=list(a%%2,c)]) +# that :=NULL together with i is now an error +DT = data.table(a=1:3, b=1:6) +test(1353.1, DT[2, b:=NULL], error="When deleting columns, i should not be provided") +test(1353.2, DT[2, c("a","b"):=list(42, NULL)], error="When deleting columns, i should not be provided") ########################## + # TO DO: Add test for fixed bug #5519 - dcast.data.table returned error when a package imported data.table, but dint happen when "depends" on data.table. This is fixed (commit 1263 v1.9.3), but not sure how to add test. # TO DO: test and highlight in docs that negatives are fine and fast in forderv (ref R wish #15644) diff --git a/src/assign.c b/src/assign.c index 5ec97cc79..440e1650e 100644 --- a/src/assign.c +++ b/src/assign.c @@ -403,6 +403,7 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values, SEXP v else thisvalue = values; // One vector applied to all columns, often NULL or NA for example if (TYPEOF(thisvalue)==NILSXP) { + if (!isNull(rows)) error("When deleting columns, i should not be provided"); anytodelete = TRUE; continue; // delete column(s) afterwards, below this loop }