Skip to content

keyby=TRUE/FALSE together with by= #4307

@jangorecki

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]

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