Skip to content

keyby=TRUE/FALSE together with by= #4307

Closed

Description

@jangorecki

I recall something similar so this FR could eventually be a duplicate already. Yes, there is #1104.

Currently, when using both by and keyby we get an error.

data.table(a=1,b=2,d=3)[, .SD, by="a", keyby=TRUE]
#Error in `[.data.table`(data.table(a = 1, b = 2, d = 3), , .SD, by = "a",  : 
#  Provide either by= or keyby= but not both

Would be useful to support such syntax, so if user wants to have a sorted groups, then just passing T/F is sufficient, and there is no need to switch between the arguments that needs to be suplied to function.

Moreover using keyby as logical is what we actually do internally, at the very top of processing by/keyby arguments. And there is a comment there: # Assign to 'by' so that by is no longer missing and we can proceed as if there were one by


Following line, the else branch, could be simplified:

by.or.keyby = if (join) "by" else c("by"[!sorted], "keyby"[sorted])[1L]

Activity

  1. self-assigned this
    on Apr 2, 2020
  2. added this to the 1.14.1 milestone on Apr 15, 2021
  3. changed the title [-]allow to use `keyby` arg as a sort flag, together with `by` argument[/-] [+]keyby=TRUE/FALSE together with by=[/+] on Apr 15, 2021
  4. modified the milestones: 1.14.9, 1.15.0 on Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions