[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

Comments

Projects
None yet
1 participant
@arunsrinivasan
Member

arunsrinivasan commented Jun 8, 2014

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 added Medium and removed Medium labels 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