Rdatatable / Rdatatable/data.table

Symbol .I consistency when not grouping

Open
#2,598 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

This has come up before I'm sure but I can't find the issue or S.O. post. Anyone remember or have the links please? I seem to remember replying to someone something like ".I is intended for use in grouping as per the documentation, but it would be good to extend it to non-grouping too". The man page still contains the words "while grouping" for .I.

Current behaviour in both v1.10.4-3 and dev :

> X = data.table(c("a","a","b","c","c"), 10:14)
> setkey(X,V1)
>  X["b"]
   V1 V2
1:  b 12       # ok
> X["b", .I]
[1] 1          # expected x's row number 3  (*1)
> X["b", .I, by=.EACHI]
   V1 I
1:  b 3        # ok
> X["b", .(.I,V2)]
   I V2
1: 1 12      # expected x's row number 3 not 1  (*2)
> X["b", .(.I,V2), by=.EACHI]
   V1 I V2
1:  b 3 12     # ok
> 

Now, which=TRUE was intended and works for the first case (*1) :

> X["b", which=TRUE]
[1] 3

but including x's row numbers inside j (*2) isn't currently possible, unless you add x's row numbers explicitly as a column first. It would be nice for .I to do what which=TRUE does in the simple case (*1) and maybe even slowly deprecate which=TRUE argument since my guess is people reach for .I first.

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.

Research direction

Start with the special-symbols.Rd man page and reproduce the supplied X["b"] examples in R, comparing .I with which=TRUE and by=.EACHI. Determine the intended non-grouping semantics and update the relevant behavior and documentation so .I reports x's row numbers consistently without grouping.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.