Closed r2evans closed 1 year ago
Erp, didn't initially realize the data.table version brought fcase
inside the call to EMA
, side-stepping the problem. The data.table
-native problem shows the same error when the calls to EMA
are inside the call to fcase
.
Motivated by https://stackoverflow.com/q/77327623/3358272, I wanted to play with the
dtplyr
version.The
dplyr
-native function works without warning/error:If we bring in
dtplyr
, we get an error:Debugging in the first conditional reveals the problem:
whereas in
dplyr
, it's more intuitively:(Note that the group has 100 rows, and the
EMA(..)
call in both implementations returns a vector of length 100.)I believe this is because in
data.table
, grouping variables tend to be of reduced size. Looking at thedata.table
-native code,I think this is somewhat "intentional" (or at least "known") in
data.table
. While the underlying behavior (cat
is length 1 due to it being a grouping variable) cannot be changed here, there is something else going on when the dplyr and data.table native implementations work without error, but thelazy_dt(df)
version fails, and therefore requiring one of two (or more?) odd-looking workarounds: