Skip to content

eval doesn't work for . in by #1298

Closed
Closed

Description

@eantonya
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 "."

Activity

  1. added this to the v1.9.6 milestone on Sep 17, 2015
  2. franknarf1 commented on Jul 30, 2019

    @franknarf1
    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 "."
    
  3. jangorecki commented on Jul 30, 2019

    @jangorecki
    Member

    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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions