Skip to content

[.data.table accept both by and keyby non-missing #1104

@jangorecki

Description

@jangorecki

I would like do conditional sort while making aggregation, I think [.data.table could be less restricted and check only if one of by and keyby is not null.

library(data.table)
dt <- data.table(a = 1:10, b = 1:5)
do_sort <- FALSE
dt[,j = .(a=sum(a)),
   by = if(!do_sort) b else NULL,
   keyby = if(do_sort) b else NULL]
# Error in `[.data.table`(dt, , j = .(a = sum(a)), by = if (!do_sort) b else NULL,  : 
#   Provide either 'by' or 'keyby' but not both

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions