Allow a character string in `which` argument of `data.table:::[.data.table`
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 38/100
Research direction
Start at the data.table:::[.data.table entry point, focusing on how the existing which values and negated joins are handled. Compare the proposed xmatch, xnomatch, imatch, and inomatch behaviors with the examples in the issue. Done means character-string values return the specified x or i row numbers while preserving existing behavior.
Written by the indexing model from the issue text.
Description
This is a feature request.
I find which argument quite confusing/counterintuitive when joining and returning i row numbers in x[i, which=NA, ...].
A join and which argument can interact in four different ways as shown below:
x = data.table(a=1:3, x=c(NA, 10, NA))
i = data.table(a=2:5, y=c(20, 10, 20, 30))
x
a x
<int> <num>
1: 1 NA
2: 2 10
3: 3 NA
i
a y
<int> <num>
1: 2 20
2: 3 10
3: 4 20
4: 5 30
x[i, on="a", which=TRUE] # (a): ok
[1] 2 3 NA NA
x[!i, on="a", which=TRUE] # (b): ok
[1] 1
x[i, on="a", which=NA] # (c): counterintuitive
[1] 3 4
x[!i, on="a", which=NA] # (d): counterintuitive
[1] 1 2
(a): row numbers of x that i matches to.
(b): row numbers of x that no i matches to.
(c): row numbers of i that have no match to x. The fact that i is not prefixed with ! makes it counterintuive.
(d): row numbers of i that have a match to x. The use of ! suggests that the cases that have no match are of interest while it is actually the opposite.
I propose to allow a character string in which with four possible values (other propositions are very welcome): c("xmatch", "xnomatch", "imatch", "inomatch") where they correspond to (a), (b), (d), and (c) scenarios, respectively. These values would work as follow:
x[i, on="a", which="xmatch"] # row number of x that i matches to
x[i, on="a", which="xnomatch"] # row numbers of x that no i matches to
x[i, on="a", which="imatch"] # row numbers of i that have a match to x
x[i, on="a", which="inomatch"] # row numbers of i that have no match to x
So, the character string specified would allow to know the type of join (whether i needs to be prefixed with ! or not) and the data.table whose row numbers should be returned.
With this feature, data.table:::[.data.table would behave as below:
fm = function(x, i, on, which){
switch(which,
xmatch = x[i, on=on, which=TRUE],
xnomatch = x[!i, on=on, which=TRUE],
inomatch = x[i, on=on, which=NA],
imatch = x[!i, on=on, which=NA])
}
fm(A, B, on="a", which="xmatch")
[1] 2 3 NA NA
fm(A, B, on="a", which="xnomatch")
[1] 1
fm(A, B, on="a", which="imatch")
[1] 1 2
fm(A, B, on="a", which="inomatch")
[1] 3 4
- Dominant language
- R
- Stars
- 3.9k
- Forks
- 1.1k
- Avg merge
- 14h 4m
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Rdatatable/data.table
-
as.data.table() recurses without end on a survival::Surv object (or any data.frame carrying one) Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Rdatatable/data.table#7887 ·
-
consistency tests
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#7853 · 3 comments ·
-
internals
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#6938 · 1 comment ·
-
encoding fread
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#5179 · 8 comments ·
-
documentation programming
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#3199 · 3 comments ·
All issues in Rdatatable/data.table
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
r-lib/pkgdepends#485 · 3 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
beginners blocker
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enviPathR OpenBuild Error Build OK Build Warning policies-accepted pre-review precheck-passed
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Bioconductor/BiocContributions#207 · 6 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
datacarpentry/semester-biology#1255 ·