Skip to content

improvement on programmatically substituting columns in expressions #2655

@arunsrinivasan

Description

@arunsrinivasan
require(data.table) # devel compiled on 3rd March 2018
dt <- data.table(x=1:5, y=6:10, z=11:15)
#    x  y  z
# 1: 1  6 11
# 2: 2  7 12
# 3: 3  8 13
# 4: 4  9 14
# 5: 5 10 15

Now we can subset cols using the .. notation conveniently as follows:

cols <- "z"
dt[, ..cols]
#     z
# 1: 11
# 2: 12
# 3: 13
# 4: 14
# 5: 15

Since ..var has a very special meaning, we could also allow this?

dt[, c(..cols, "x")]

Currently, it errors as follows:

# Error in eval(jsub, SDenv, parent.frame()) : object '..cols' not found

Haven't really given it a lot of thought.. Just came across it and wanted to file it as an issue so that it doesn't get lost.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementprogrammingparameterizing queries: get, mget, eval, envtop requestOne of our most-requested issues

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions