Skip to content

[R-Forge #5357] don't die when lhs of := has zero length #343

@arunsrinivasan

Description

@arunsrinivasan

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.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions