Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative way to dynamic symbol usage in j #2884

Closed
renkun-ken opened this issue May 16, 2018 · 3 comments · Fixed by #4304
Closed

Alternative way to dynamic symbol usage in j #2884

renkun-ken opened this issue May 16, 2018 · 3 comments · Fixed by #4304
Labels
programming parameterizing queries: get, mget, eval, env

Comments

@renkun-ken
Copy link
Member

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.

@jangorecki
Copy link
Member

jangorecki commented May 16, 2018

I like the idea, somehow similar to substitute() where env argument refers to alias. We could also substitute function names this way.

@jangorecki
Copy link
Member

jangorecki commented Mar 22, 2020

It seems that my PR #4304 actually re-invents and implements what @renkun-ken wrote in this issue, + maybe call arg names substitution :)

@renkun-ken
Copy link
Member Author

Didn't remember this issue. Explains why your nice solution looks so great to me. 😄

@jangorecki jangorecki added the programming parameterizing queries: get, mget, eval, env label Apr 5, 2020
@jangorecki jangorecki linked a pull request Jun 17, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
programming parameterizing queries: get, mget, eval, env
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants