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
I would like do conditional sort while making aggregation, I think
[.data.tablecould be less restricted and check only if one ofbyandkeybyis not null.