Submitted by: Eduard Antonyan; Assigned to: Arun ; R-Forge link
I frequently remove many columns by doing the following:
d = data.table(a = 1:5, b1 = 1:5, b2 = 1:5)
d[, grep("b", names(d)) := NULL]
Unfortunately the above dies when the search fails and the LHS is actually empty (integer(0) or character(0)):
d[, grep("c", names(d)) := NULL]
# Error in `[.data.table`(d, , `:=`(grep("c", names(d)), NULL)) :
# Logical error in assign, no column positions passed to assign
I'd much rather this resulted in no action + a warning.