Using row index `.I` for joins as an argument to `on=`
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with the reproducible R example in the issue and review issue #1494, which the report identifies as related. Done means joins can use the row index through on= without creating a temporary row_index column, either by fixing .I behavior or introducing a clearer .ROWI/.ROWINDEX alternative.
Written by the indexing model from the issue text.
Description
library(data.table)
dt1 = CJ(a=1:5, b=c("yes","no"))
# Key: <a, b>
# Index: <b>
# a b
# <int> <char>
# 1: 1 no
# 2: 1 yes
# 3: 2 no
# 4: 2 yes
# 5: 3 no
# 6: 3 yes
# 7: 4 no
# 8: 4 yes
# 9: 5 no
# 10: 5 yes
dt2 = dt1[b == "yes", list(.RESULT = list(seq(0, a))), by=.I][,unlist(.RESULT), by=I]
# I V1
# <int> <int>
# 1: 2 0
# 2: 2 1
# 3: 4 0
# 4: 4 1
# 5: 4 2
# 6: 6 0
# 7: 6 1
# 8: 6 2
# 9: 6 3
# 10: 8 0
# 11: 8 1
# 12: 8 2
# 13: 8 3
# 14: 8 4
# 15: 10 0
# 16: 10 1
# 17: 10 2
# 18: 10 3
# 19: 10 4
# 20: 10 5
# I V1
## This is what I want to do but it gives an error
# dt1 <- dt1[dt2, on=list(.I="I")]
# Error in colnamesInt(x, names(on), check_dups = FALSE) :
# argument specifying columns received non-existing column(s): cols[1]='.I'
## This is what I need to do but it is so much longer and complicated (and probably slower)
tmp <- copy(dt1)
tmp <- tmp[, row_index:=.I][dt2, on = list(row_index=I)]
tmp[, row_index:=NULL]
dt1 <- tmp
rm(tmp)
dt1
# Key: <a, b>
# a b V1
# <int> <char> <int>
# 1: 1 yes 0
# 2: 1 yes 1
# 3: 2 yes 0
# 4: 2 yes 1
# 5: 2 yes 2
# 6: 3 yes 0
# 7: 3 yes 1
# 8: 3 yes 2
# 9: 3 yes 3
# 10: 4 yes 0
# 11: 4 yes 1
# 12: 4 yes 2
# 13: 4 yes 3
# 14: 4 yes 4
# 15: 5 yes 0
# 16: 5 yes 1
# 17: 5 yes 2
# 18: 5 yes 3
# 19: 5 yes 4
# 20: 5 yes 5
# a b V1
To make this work, issue #1494 probably needs to be fixed or introduce a different .ROWI that doesn't have .I's behavior.
(.ROWI or .ROWINDEX is anyway clearer than .I)
- 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 ·