retaining key during outer join

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

Nobody has claimed this yet.

Assessment

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

Research direction

Start by running the reproducible R example with data.table 1.14.0 and inspect the key after the outer join that includes the unmatched value 5. Compare the keyed and nomatch = NULL results; done means the key behavior is consistent for the unmatched-row case and any relevant regression is covered.

Written by the indexing model from the issue text.

Description

joins

reported over email, quite possibly it is a duplicate of existing issue

#R 4.0.3
#data.table is 1.14.0
library(data.table)
x <- data.table(letter = c("a", "b", "a", "c", "d"),
                number = c(1, NA, 3, 4, 5),
                val = c(0, 0, 100, 300, 50))
setkey(x, letter, number)

key(x)
#[1] "letter" "number" 

x[J("a", c(1, 3))]
#   letter number val
#1:      a      1   0
#2:      a      3 100

key(x[J("a", c(1, 3))])
#[1] "letter" "number"

x[J("a", c(1, 3)), nomatch = NULL]
#   letter number val
#1:      a      1   0
#2:      a      3 100

key(x[J("a", c(1, 3)), nomatch = NULL])
#[1] "letter" "number"

x[J("a", c(1, 3, 5))]
#   letter number val
#1:      a      1   0
#2:      a      3 100
#3:      a      5  NA

key(x[J("a", c(1, 3, 5))])
#NULL
#this is odd, as the key disappears

x[J("a", c(1, 3, 5)), nomatch = NULL]
#   letter number val
#1:      a      1   0
#2:      a      3 100

key(x[J("a", c(1, 3, 5)), nomatch = NULL])
#[1] "letter" "number"
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.