.SD ignores locally updated vectors in j

Open
#7,431 4 comments 0 reactions 1 assignee View on GitHub

@venom1204 is already working on this.

Since Nov 19, 2025.

Assessment

This issue has not been assessed yet.

Description

documentation

I would expect both expressions give the same result.
Filtering in i is irrelevant, I have kept it to reflect my use case.

data.table(a = 1:3, b = 1:3, d = 1:3
)[a %in% 1:2, {
  b[d == 2L] <- 0L
  .SD
}]
#       a     b     d
#1:     1     1     1
#2:     2     2     2

data.table(a = 1:3, b = 1:3, d = 1:3
)[a %in% 1:2, {
  b[d == 2L] <- 0L
  .(a, b, d)
}]
#       a     b     d
#1:     1     1     1
#2:     2     0     2

1.17.0

workaround for now:

data.table::data.table(a = 1:3, b = 1:3, d = 1:3
)[a %in% 1:2, {
  b[d == 2L] <- 0L
  .SD
}, env = list(.SD = as.list(c("a","b","d")))]
Dominant language
R
Stars
3.9k
Forks
1.1k
Avg merge
14h 4m
Merged PRs (30d)
4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Rdatatable/data.table

All issues in Rdatatable/data.table

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.