Subsetting data.table using variables with same name as column

For now, a temporary solution could be,

`..` <- function (..., .env = globalenv())
{
  get(deparse(substitute(...)), env = .env)
}

..(a)
## [1] "b"

dt[a==..(a)]
##    a b  c
## 1: b a 15
## 2: b a 11
## 3: b b  8
## 4: b b  4
## 5: b c  5
## 6: b c 12

Though this looks elegant, I am still waiting for a more robust solution to such scope issues.

Edited according to @mnel’s suggestion,

`..` <- function (..., .env = sys.parent(2))
{
  get(deparse(substitute(...)), env = .env)
}

Leave a Comment