Skip to content

Inconsistency of excluding columns in j vs. .SDcols #5193

@MichaelChirico

Description

@MichaelChirico
DT = data.table(a = 1:5)

Consider two approaches to dropping a non-existent column:

DT[, !"b"]
# vs
DT[, .SD, .SDcols = !"b"]

The former is currently a warning, the latter an error:

# Warning message:
# In `[.data.table`(available_configs, , !"abc") :
#   column(s) not removed because not found: [abc]

# vs
# Error in `[.data.table`(available_configs, , .SD, .SDcols = !"abc") : 
#   Some items of .SDcols are not column names: [abc]

It seems to me the latter should also be a warning.

The use case here is excluding a column programmatically, where it may or may not be present in the table -- I'm trying to exclude-if-present.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions