Silently in-place merge last row with on= when multiple rows match
A pull request for this has already been merged.
- #4370 by @jangorecki — merged
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Re-run the minimal example using d1[d2, y := y, on = "id"] and trace how duplicate matches are handled during the in-place update. Review linked pull request #4370 for work already attempted, then identify the relevant join-update tests or entry points; done should include a defined signal for multiple matches.
Written by the indexing model from the issue text.
Description
data[dt, x := y, on = "group"] performs in-place adding columns from dt to data on corresponding group. Currently, if dt has multiple rows that match a certain group, it seems the last row in that group will be taken, silently. I'm not sure if it is a designed behavior, but for me such multiple matching in most cases is simply a mistake and I should take a closer look at why dt has multiple matches on group, which often suggests that I made a mistake creating dt or something is missing in dt.
A minimal example is following:
library(data.table)
d1 <- data.table(id = 1:10, x = 1:10)
d1
#> id x
#> 1: 1 1
#> 2: 2 2
#> 3: 3 3
#> 4: 4 4
#> 5: 5 5
#> 6: 6 6
#> 7: 7 7
#> 8: 8 8
#> 9: 9 9
#> 10: 10 10
d2 <- data.table(id = c(1, 1, 2, 3, 3), y = c(1, 2, 2, 3, 4))
d2
#> id y
#> 1: 1 1
#> 2: 1 2
#> 3: 2 2
#> 4: 3 3
#> 5: 3 4
d1[d2, y := y, on = "id"]
d1
#> id x y
#> 1: 1 1 2
#> 2: 2 2 2
#> 3: 3 3 4
#> 4: 4 4 NA
#> 5: 5 5 NA
#> 6: 6 6 NA
#> 7: 7 7 NA
#> 8: 8 8 NA
#> 9: 9 9 NA
#> 10: 10 10 NA
Would it make sense if a signal is generated for such case so that the problem can be spotted eariler?
- 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 ·