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

[R-Forge #5732] Failure to evaluate parsed expression in list in j (not using :=) #472

Closed
arunsrinivasan opened this issue Jun 8, 2014 · 0 comments
Assignees
Milestone

Comments

@arunsrinivasan
Copy link
Member

Submitted by: Benjamin Barnes; Assigned to: Nobody; R-Forge link

library(data.table)
## data.table 1.9.3  For help type: help("data.table")

set.seed(100)
nrow <- 100
DT <- data.table(aa = sample(letters[1:5], nrow, replace = TRUE), bb = rnorm(nrow))
sumExpr <- parse(text = "sum(bb, na.rm = TRUE)")
meanExpr <- parse(text = "mean(bb, na.rm = TRUE)")

## These work
DT[, eval(sumExpr), by = aa]
DT[, eval(meanExpr), by = aa]

## This does not work
DT[, list(mySum = eval(sumExpr), myMean = eval(meanExpr)), by = aa]
## Error in `[.data.table`(DT, , list(mySum = eval(sumExpr), myMean = eval(meanExpr)),  : 
##   Unsupported type 'expression'

## This works
DT[, {
    out <- list(mySum = eval(sumExpr), myMean = eval(meanExpr))
    lapply(out, eval, .SD)
    }, by = aa]

Perhaps there has been a change of paradigm concerning evaluation of expressions in data.tables - if so, please excuse my ignorance!

@arunsrinivasan arunsrinivasan added this to the v1.9.4 milestone Jun 19, 2014
@arunsrinivasan arunsrinivasan self-assigned this Jun 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant