Skip to content

Alternative way to dynamic symbol usage in j #2884

@renkun-ken

Description

@renkun-ken

Using dynamically determined symbol in j can be quite annoying (as discussed in #633, #2589).

I'm not sure if the following idea makes sense, which seems easier to implement and nicer to look at for me.

library(data.table)
dt <- data.table(id = rep(1:2, 5), x1 = rnorm(10), x2 = rnorm(10), y1 = rnorm(10), y2 = rnorm(10))
dt[, .(xsum = sum(x), ysum = sum(y)), by = id, alias = c(x = "x1", y = "y2")]

In the above example, if a new argument like alias is introduced, a named character vector would give fixed names to dynamically determined symbols, which makes it much easier to use them in j.

Some new problems may occur such as when x or y are already defined in dt. But the syntax looks much cleaner if the dynamic symbols can be determined outside dt.

Metadata

Metadata

Assignees

No one assigned

    Labels

    programmingparameterizing queries: get, mget, eval, env

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions