0

How do I get the following code to recognize the second a in dt[a == a,] as an external variable with value 3?

a <- 3
dt <- data.table(a = seq(5), b = rnorm(5))
dt[a==a,]

Expected output should be the same as the output from dt[a==3,].

EDIT:

I'm aware that there's a solution available here: Subsetting data.table using variables with same name as column

But the answer is from 4 years ago and the first comment mentions that the package maintainers are aware of this scoping issue and are working to fix it. So, is there now a straightforward way to address this?

user3294195
  • 1,748
  • 1
  • 19
  • 36
  • 3
    I think the recent ones are [here](https://stackoverflow.com/questions/32738499/data-table-assignments-when-variable-has-same-name-as-a-column) or [here](https://stackoverflow.com/questions/48256904/datatable-column-name-is-the-same-as-global-environment-value) – akrun Jun 06 '18 at 03:53
  • 1
    @akrun You can click the edit button on the "already has an answer" box to add more links (a feature added a year or so ago, I think) – Frank Jun 06 '18 at 15:59

0 Answers0