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

eval doesn't work for . in by #1298

Closed
eantonya opened this issue Aug 27, 2015 · 2 comments
Closed

eval doesn't work for . in by #1298

eantonya opened this issue Aug 27, 2015 · 2 comments
Assignees
Labels
Milestone

Comments

@eantonya
Copy link
Contributor

d = data.table(a = 1)
q = quote(.(a))

d[, eval(q)]
#   a
#1: 1

d[, 1, by = .(a)]
#   a V1
#1: 1  1

# the problem
d[, 1, by = eval(q)]
#Error in eval(expr, envir, enclos) : could not find function "."
@franknarf1
Copy link
Contributor

Somehow this is happening again in this SO example: https://stackoverflow.com/q/57253159/1191259

library(data.table)
dt_mtcars <- as.data.table(mtcars)
group = ".(cyl, gear)"
dt_mtcars[, .(mean_mpg = mean(mpg), median_mpg = median(mpg)), by=eval(parse(text=group))]
# Error in .(cyl, gear) : could not find function "."

@jangorecki
Copy link
Member

jangorecki commented Jul 30, 2019

parse return an expression call, it will work by adding [[1L]]

dt_mtcars[, .(mean_mpg = mean(mpg), median_mpg = median(mpg)), by=eval(parse(text=group)[[1L]])]

I don't think it qualify for re-opening, it is easy to investigate what is being passed to eval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants