From 388ef8c7663753bad09180e19805f2fb87f5ed2b Mon Sep 17 00:00:00 2001 From: coffeecookey Date: Mon, 29 Dec 2025 03:14:23 +0530 Subject: [PATCH 1/7] 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/7] 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/7] 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/7] 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") From 47bb2c390b7800a6f712b71a2e23988ba1fae3e1 Mon Sep 17 00:00:00 2001 From: sisyphuswastaken Date: Wed, 31 Dec 2025 15:13:26 +0530 Subject: [PATCH 5/7] revised implementation of NSE in cube --- ..Rcheck/00check.log | 13 +++++++++++++ Makevars | 3 +++ R/groupingsets.R | 42 +++++++++++++++++++++++++++++++++++------- 3 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 ..Rcheck/00check.log create mode 100644 Makevars diff --git a/..Rcheck/00check.log b/..Rcheck/00check.log new file mode 100644 index 0000000000..2d743cd4d3 --- /dev/null +++ b/..Rcheck/00check.log @@ -0,0 +1,13 @@ +* using log directory ‘/Users/tanishaojha/Desktop/Code-folder/data.table/..Rcheck’ +* using R version 4.5.1 (2025-06-13) +* using platform: aarch64-apple-darwin20 +* R was compiled by + Apple clang version 16.0.0 (clang-1600.0.26.6) + GNU Fortran (GCC) 14.2.0 +* running under: macOS Sequoia 15.5 +* using session charset: UTF-8 +* checking for file ‘./DESCRIPTION’ ... ERROR +Required fields missing or empty: + ‘Author’ ‘Maintainer’ +* DONE +Status: 1 ERROR diff --git a/Makevars b/Makevars new file mode 100644 index 0000000000..dd8d74e972 --- /dev/null +++ b/Makevars @@ -0,0 +1,3 @@ +CPPFLAGS += -I/opt/homebrew/opt/gettext/include +LDFLAGS += -L/opt/homebrew/opt/gettext/lib + diff --git a/R/groupingsets.R b/R/groupingsets.R index 21ec65bd42..26e01e2a3c 100644 --- a/R/groupingsets.R +++ b/R/groupingsets.R @@ -29,26 +29,54 @@ 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) + bysub = substitute(by) + names_x = names(x) + + allbyvars = intersect(all.vars(bysub), names_x) usesSD = any(all.vars(jj) == ".SD") + if (usesSD) { if (missing(.SDcols)) { - .SDcols = names(x)[vapply(x, is.numeric, logical(1L))] + ansvars = sdvars = setdiff(unique(names_x), union(by, allbyvars)) + ansvals = match(ansvars, names_x) } 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)) + call_name = as.character(sub.result[[1L]]) + if (call_name %in% c("patterns", "is.numeric", "is.character", "is.factor")) { + .SDcols = eval_with_cols(sub.result, names_x) + } else { + .SDcols = eval(sub.result, parent.frame()) } + } else { + .SDcols = eval(sub.result, parent.frame()) + } + if (is.character(.SDcols)) { + if (!all(idx = .SDcols %chin% names_x)) + stopf("Some items of .SDcols are not column names: %s", + paste(.SDcols[!idx], collapse = ", ")) + ansvars = sdvars = .SDcols + ansvals = match(ansvars, names_x) + } else if (is.numeric(.SDcols)) { + ansvals = as.integer(.SDcols) + ansvars = sdvars = names_x[ansvals] + } else if (is.logical(.SDcols)) { + if (length(.SDcols) != length(names_x)) + stopf(".SDcols is a logical vector of length %d but there are %d columns", + length(.SDcols), length(names_x)) + ansvals = which(.SDcols) + ansvars = sdvars = names_x[ansvals] + } else { + stopf(".SDcols must be character, numeric, or logical") } } } 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 e9876cb8af7ad1f4df58607542263428efd3c5b4 Mon Sep 17 00:00:00 2001 From: sisyphuswastaken Date: Wed, 31 Dec 2025 15:31:52 +0530 Subject: [PATCH 6/7] cleaning up the code --- R/groupingsets.R | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/R/groupingsets.R b/R/groupingsets.R index 26e01e2a3c..4890bf5652 100644 --- a/R/groupingsets.R +++ b/R/groupingsets.R @@ -29,15 +29,12 @@ 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) bysub = substitute(by) names_x = names(x) - allbyvars = intersect(all.vars(bysub), names_x) usesSD = any(all.vars(jj) == ".SD") - if (usesSD) { if (missing(.SDcols)) { ansvars = sdvars = setdiff(unique(names_x), union(by, allbyvars)) @@ -55,9 +52,9 @@ cube.data.table = function(x, j, by, .SDcols, id = FALSE, label = NULL, ...) { .SDcols = eval(sub.result, parent.frame()) } if (is.character(.SDcols)) { - if (!all(idx = .SDcols %chin% names_x)) - stopf("Some items of .SDcols are not column names: %s", - paste(.SDcols[!idx], collapse = ", ")) + idx = .SDcols %chin% names_x + if (any(!idx)) + stopf("Some items of .SDcols are not column names: %s", toString(.SDcols[!idx])) ansvars = sdvars = .SDcols ansvals = match(ansvars, names_x) } else if (is.numeric(.SDcols)) { @@ -65,8 +62,7 @@ cube.data.table = function(x, j, by, .SDcols, id = FALSE, label = NULL, ...) { ansvars = sdvars = names_x[ansvals] } else if (is.logical(.SDcols)) { if (length(.SDcols) != length(names_x)) - stopf(".SDcols is a logical vector of length %d but there are %d columns", - length(.SDcols), length(names_x)) + stopf(".SDcols is a logical vector of length %d but there are %d columns", length(.SDcols), length(names_x)) ansvals = which(.SDcols) ansvars = sdvars = names_x[ansvals] } else { @@ -76,7 +72,6 @@ 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 2a15cb9d4cbbad25e27a240b4fe83c05da43502b Mon Sep 17 00:00:00 2001 From: sisyphuswastaken Date: Wed, 31 Dec 2025 15:37:35 +0530 Subject: [PATCH 7/7] more cleaning --- R/groupingsets.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/groupingsets.R b/R/groupingsets.R index 4890bf5652..da0e8fe3d0 100644 --- a/R/groupingsets.R +++ b/R/groupingsets.R @@ -53,7 +53,7 @@ cube.data.table = function(x, j, by, .SDcols, id = FALSE, label = NULL, ...) { } if (is.character(.SDcols)) { idx = .SDcols %chin% names_x - if (any(!idx)) + if (!all(idx)) stopf("Some items of .SDcols are not column names: %s", toString(.SDcols[!idx])) ansvars = sdvars = .SDcols ansvals = match(ansvars, names_x)