When I run...
library(data.table) DT = CJ(id = 1, id2 = 1:3)[, .( d = as.IDate(\"2017-01-01\")+1:10, v = id*10 + id2*1:10 ), by=.(id, id2)] plotDT = DT[
One working hack is to write j like
j
with(copy(.SD), {yada yada})
or similar, which ensures that references are to the per-group copy of .SD and don't get conflated.
.SD