Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyby=TRUE/FALSE together with by= #4307

Closed
jangorecki opened this issue Mar 17, 2020 · 0 comments · Fixed by #4338
Closed

keyby=TRUE/FALSE together with by= #4307

jangorecki opened this issue Mar 17, 2020 · 0 comments · Fixed by #4338
Assignees
Milestone

Comments

@jangorecki
Copy link
Member

jangorecki commented Mar 17, 2020

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]

jangorecki added a commit that referenced this issue Apr 2, 2020
@jangorecki jangorecki self-assigned this Apr 2, 2020
@mattdowle mattdowle added this to the 1.14.1 milestone Apr 15, 2021
@mattdowle mattdowle changed the title allow to use keyby arg as a sort flag, together with by argument keyby=TRUE/FALSE together with by= Apr 15, 2021
@jangorecki jangorecki modified the milestones: 1.14.9, 1.15.0 Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants