Deselect columns using - or ! also with .() or list()

Open
#2,878 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
data

Research direction

Reproduce the listed flights examples in R and trace the column-selection entry point used by DT[i, j], focusing on unary - and ! applied to list() or .(). Done when the list and dot-list cases deselect the same columns as the working c() cases, with regression coverage for the behavior.

Written by the indexing model from the issue text.

Description

feature request

Columns can be deselected with - or ! e.g.:
flights[, -c("arr_delay", "dep_delay")]

but it does not work with lists
flights[, -.(arr_delay, dep_delay)]

Error in -list(arr_delay, dep_delay) : invalid argument to unary operator

for me it would be a nice feature if deselecting works also for lists.
It works for many other cases as shown below.

# [Minimal reproducible example]
library(data.table)
flights <- fread("https://raw.githubusercontent.com/wiki/arunsrinivasan/flights/NYCflights14/flights14.csv")
flights[, -c("arr_delay", "dep_delay")]
flights[, !c("arr_delay", "dep_delay")]
select_cols <- c("arr_delay", "dep_delay")
flights[ , !..select_cols]
flights[ , -..select_cols]
flights[ , !..select_cols]
flights[ , -select_cols, with = FALSE]
flights[, -(year:day)]
flights[, !(year:day)]
# flights[, -.(arr_delay, dep_delay)] #Works not
# flights[, !.(arr_delay, dep_delay)] #Works not
# flights[, -list(arr_delay, dep_delay)] #Works not
# flights[, !list(arr_delay, dep_delay)] #Works not
Output of sessionInfo() R version 3.5.0 (2018-04-23) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS: /usr/local/lib64/R/lib/libRblas.so
LAPACK: /usr/local/lib64/R/lib/libRlapack.so

locale:
[1] C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] data.table_1.11.2

loaded via a namespace (and not attached):
[1] compiler_3.5.0 curl_3.2

Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.