From 388ef8c7663753bad09180e19805f2fb87f5ed2b Mon Sep 17 00:00:00 2001 From: coffeecookey Date: Mon, 29 Dec 2025 03:14:23 +0530 Subject: [PATCH 1/4] implementing NSE to cube --- R/groupingsets.R | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/R/groupingsets.R b/R/groupingsets.R index f5fc2101f1..f04c506fc7 100644 --- a/R/groupingsets.R +++ b/R/groupingsets.R @@ -29,6 +29,25 @@ 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))] + } 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)))) From 3e96dfc95a595139f6b6486a6a2924f8aeac6d0f Mon Sep 17 00:00:00 2001 From: sisyphuswastaken Date: Mon, 29 Dec 2025 03:41:39 +0530 Subject: [PATCH 2/4] implementing NSE in cube --- R/groupingsets.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/groupingsets.R b/R/groupingsets.R index f04c506fc7..54ddd26194 100644 --- a/R/groupingsets.R +++ b/R/groupingsets.R @@ -29,7 +29,7 @@ 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 + #implementing NSE in cube jj = substitute(j) usesSD = any(all.vars(jj) == ".SD") if (usesSD) { @@ -48,6 +48,7 @@ cube.data.table = function(x, j, by, .SDcols, id = FALSE, label = NULL, ...) { } 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)))) From e1eb87a5f60d8292579c326dcdcfbd5b6193903f Mon Sep 17 00:00:00 2001 From: sisyphuswastaken Date: Mon, 29 Dec 2025 03:49:27 +0530 Subject: [PATCH 3/4] removed trailing whitespace --- R/groupingsets.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/groupingsets.R b/R/groupingsets.R index 54ddd26194..93e36899e1 100644 --- a/R/groupingsets.R +++ b/R/groupingsets.R @@ -29,7 +29,8 @@ 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 + + #implementing NSE in cube jj = substitute(j) usesSD = any(all.vars(jj) == ".SD") if (usesSD) { @@ -48,7 +49,7 @@ cube.data.table = function(x, j, by, .SDcols, id = FALSE, label = NULL, ...) { } 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)))) From b6adef94fabc78213edb4099594abd5b44fd195b Mon Sep 17 00:00:00 2001 From: sisyphuswastaken Date: Mon, 29 Dec 2025 03:53:21 +0530 Subject: [PATCH 4/4] removed trailing whitespace --- R/groupingsets.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/groupingsets.R b/R/groupingsets.R index 93e36899e1..21ec65bd42 100644 --- a/R/groupingsets.R +++ b/R/groupingsets.R @@ -29,7 +29,6 @@ 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")