Skip to content

Commit

Permalink
add subset and dogroups support for columns of type expression (#5631)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Sep 8, 2024
1 parent f0aaaf9 commit 6a2bf2e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ rowwiseDT(
#> 3: 5 6 c ~a + b
```

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.

## BUG FIXES

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.
Expand Down
5 changes: 5 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -19222,3 +19222,8 @@ if (test_bit64) {
test(2288.5, rbind(a,d), data.table(list(as.integer64(1), as.integer64(2), 3.5, 4L)))
test(2288.6, rbind(d,a), data.table(list(3.5, 4L, as.integer64(1), as.integer64(2))))
}

# support column type 'expression' #5596
dt = data.table(a=1:2, b=expression(1,2))
test(2289.1, dt[1,], data.table(a=1L, b=expression(1)))
test(2289.2, dt[,b,a], dt)
2 changes: 1 addition & 1 deletion src/dogroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ SEXP dogroups(SEXP dt, SEXP dtcols, SEXP groups, SEXP grpcols, SEXP jiscols, SEX

for(int i=0; i<length(SDall); ++i) {
SEXP this = VECTOR_ELT(SDall, i);
if (SIZEOF(this)==0)
if (SIZEOF(this)==0 && TYPEOF(this)!=EXPRSXP)
internal_error(__func__, "size-0 type %d in .SD column %d should have been caught earlier", TYPEOF(this), i); // # nocov
if (LENGTH(this) != maxGrpSize)
internal_error(__func__, "SDall %d length = %d != %d", i+1, LENGTH(this), maxGrpSize); // # nocov
Expand Down
2 changes: 1 addition & 1 deletion src/subset.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void subsetVectorRaw(SEXP ans, SEXP source, SEXP idx, const bool anyNA)
for (int i=0; i<n; i++) { SET_STRING_ELT(ans, i, sp[idxp[i]-1]); }
}
} break;
case VECSXP : {
case VECSXP: case EXPRSXP: {
const SEXP *sp = SEXPPTR_RO(source);
if (anyNA) {
for (int i=0; i<n; i++) { int elem = idxp[i]; SET_VECTOR_ELT(ans, i, elem==NA_INTEGER ? R_NilValue : sp[elem-1]); }
Expand Down

0 comments on commit 6a2bf2e

Please sign in to comment.