diff --git a/NEWS.md b/NEWS.md index 58e9d6fbee..141385b010 100644 --- a/NEWS.md +++ b/NEWS.md @@ -282,6 +282,8 @@ 37. `rbindlist` now returns correct idcols for lists with different length vectors, [#3785](https://github.com/Rdatatable/data.table/issues/3785), [#3786](https://github.com/Rdatatable/data.table/pull/3786). Thanks to @shrektan for the report and fix. +39. `DT[ , !rep(FALSE, ncol(DT)), with=FALSE]` correctly returns the full table, [#3013](https://github.com/Rdatatable/data.table/issues/3013) and [#2917](https://github.com/Rdatatable/data.table/issues/2917). Thanks @alexnss and @DavidArenburg for the reports. + #### NOTES 1. `rbindlist`'s `use.names="check"` now emits its message for automatic column names (`"V[0-9]+"`) too, [#3484](https://github.com/Rdatatable/data.table/pull/3484). See news item 5 of v1.12.2 below. diff --git a/R/data.table.R b/R/data.table.R index 790a6eb475..646fa15d6a 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -650,7 +650,7 @@ replace_dot_alias = function(e) { j = eval(jsub, lapply(substring(..syms,3L), get, pos=parent.frame()), parent.frame()) } if (is.logical(j)) j <- which(j) - if (!length(j)) return( null.data.table() ) + if (!length(j) && !notj) return( null.data.table() ) if (is.factor(j)) j = as.character(j) # fix for FR: #4867 if (is.character(j)) { if (notj) { @@ -680,7 +680,8 @@ replace_dot_alias = function(e) { if (any(j>0L)) stop("j mixes positives and negatives") j = seq_along(x)[j] # all j are <0 here } - if (notj && length(j)) j = seq_along(x)[-j] + # 3013 -- handle !FALSE in column subset in j via logical+with + if (notj) j = seq_along(x)[if (length(j)) -j else TRUE] if (!length(j)) return(null.data.table()) return(.Call(CsubsetDT, x, irows, j)) } else { diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 1c6986b3f4..7da897e1c9 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -15984,6 +15984,10 @@ test(2102.1, cut(ID, breaks = br), as.IDate(cut(D, breaks=br))) test(2102.2, cut(ID, breaks = '1 year'), as.IDate(cut(D, breaks = '1 year'))) test(2102.3, cut(ID, breaks = '6 months'), as.IDate(cut(D, breaks = '6 months'))) +# DT[ , !rep(FALSE, ncol(DT)), with=FALSE] would exit before doing !, #3013 +test(2103, DT[ , !rep(FALSE, 2L), with=FALSE], DT) + + ################################### # Add new tests above this line # ###################################