Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions R/groupingsets.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ cube.data.table = function(x, j, by, .SDcols, id = FALSE, label = NULL, ...) {
stopf("Argument 'id' must be a logical scalar.")
if (missing(j))
stopf("Argument 'j' is required")
#implementing NSE in cube
jj = substitute(j)
usesSD = any(all.vars(jj) == ".SD")
if (usesSD) {
if (missing(.SDcols)) {
.SDcols = names(x)[vapply(x, is.numeric, logical(1L))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you know SDcols needs to be numeric, for example there are aggregate functions that works on character.

} else {
sub.result = substitute(.SDcols)
if (is.call(sub.result)) {
#.SDcols = eval_with_cols(sub.result, names(x))
check_var = eval_with_cols(sub.result, names(x))
if (!is.null(check_var)) {
.SDcols = eval_with_cols(sub.result, names(x))
}
}
}
} else {
.SDcols = NULL
}

# generate grouping sets for cube - power set: http://stackoverflow.com/a/32187892/2490497
n = length(by)
keepBool = sapply(2L^(seq_len(n)-1L), function(k) rep(c(FALSE, TRUE), times=k, each=((2L^n)/(2L*k))))
Expand Down
Loading