`keyby` option for `unique`

Open
#1,245 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
r
Domain
data

Research direction

Start in duplicated.data.table, where the issue suggests handling keyby alongside by, and compare how [.data.table handles keyby. Verify the equivalent of setkeyv(unique(dt, by=char_vars), char_vars), including rejection when both by and keyby are supplied; finish by checking the existing unique and duplicated behavior.

Written by the indexing model from the issue text.

Description

feature request

It would be nice to have a parallel keyby option for unique which would key a data.table just as [.data.table does.

Hopefully this is clear enough, but for further illustration, it would be equivalent to setkeyv(unique(dt, by=char_vars), char_vars). This doesn't add to the complexity of data.table since this argument already exists in another function.

Should be able to add this to duplicated.data.table pretty easily:

if (!missing(keyby)) {
    if (!missing(by)) stop("Provide either 'by' or 'keyby' but not both")
    by=bysub=substitute(keyby)
}
if (!missing(keyby)) {
        setkeyv(ans,names(ans)[seq_along(byval)])
    } 
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.