Skip to content

Commit 6a2bf2e

Browse files
add subset and dogroups support for columns of type expression (#5631)
* add subset and dogroups support for columns of type expression * narrow NEWS item --------- Co-authored-by: Michael Chirico <[email protected]> Co-authored-by: Michael Chirico <[email protected]>
1 parent f0aaaf9 commit 6a2bf2e

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ rowwiseDT(
2525
#> 3: 5 6 c ~a + b
2626
```
2727

28+
2. Limited support for subsetting or aggregating columns of type `expression`, [#5596](https://github.com/Rdatatable/data.table/issues/5596). Thanks to @tsp for the report, and @ben-schwen for the fix.
29+
2830
## BUG FIXES
2931

3032
1. Using `print.data.table()` with character truncation using `datatable.prettyprint.char` no longer errors with `NA` entries, [#6441](https://github.com/Rdatatable/data.table/issues/6441). Thanks to @r2evans for the bug report, and @joshhwuu for the fix.

inst/tests/tests.Rraw

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19222,3 +19222,8 @@ if (test_bit64) {
1922219222
test(2288.5, rbind(a,d), data.table(list(as.integer64(1), as.integer64(2), 3.5, 4L)))
1922319223
test(2288.6, rbind(d,a), data.table(list(3.5, 4L, as.integer64(1), as.integer64(2))))
1922419224
}
19225+
19226+
# support column type 'expression' #5596
19227+
dt = data.table(a=1:2, b=expression(1,2))
19228+
test(2289.1, dt[1,], data.table(a=1L, b=expression(1)))
19229+
test(2289.2, dt[,b,a], dt)

src/dogroups.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ SEXP dogroups(SEXP dt, SEXP dtcols, SEXP groups, SEXP grpcols, SEXP jiscols, SEX
140140

141141
for(int i=0; i<length(SDall); ++i) {
142142
SEXP this = VECTOR_ELT(SDall, i);
143-
if (SIZEOF(this)==0)
143+
if (SIZEOF(this)==0 && TYPEOF(this)!=EXPRSXP)
144144
internal_error(__func__, "size-0 type %d in .SD column %d should have been caught earlier", TYPEOF(this), i); // # nocov
145145
if (LENGTH(this) != maxGrpSize)
146146
internal_error(__func__, "SDall %d length = %d != %d", i+1, LENGTH(this), maxGrpSize); // # nocov

src/subset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void subsetVectorRaw(SEXP ans, SEXP source, SEXP idx, const bool anyNA)
7979
for (int i=0; i<n; i++) { SET_STRING_ELT(ans, i, sp[idxp[i]-1]); }
8080
}
8181
} break;
82-
case VECSXP : {
82+
case VECSXP: case EXPRSXP: {
8383
const SEXP *sp = SEXPPTR_RO(source);
8484
if (anyNA) {
8585
for (int i=0; i<n; i++) { int elem = idxp[i]; SET_VECTOR_ELT(ans, i, elem==NA_INTEGER ? R_NilValue : sp[elem-1]); }

0 commit comments

Comments
 (0)