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

Error in eval() for tbl_dt #585

Closed
nirski opened this issue Sep 8, 2014 · 5 comments
Closed

Error in eval() for tbl_dt #585

nirski opened this issue Sep 8, 2014 · 5 comments
Assignees
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@nirski
Copy link

nirski commented Sep 8, 2014

Boolean variables in tbl_dt are not evaluated when there are no other filters.

This gets filtered:

> data.frame(x = c(1, 1, 2), r = c(T, F, T)) %>% tbl_dt %>% filter(r, x == 1)
Source: local data table [1 x 2]

  x    r
1 1 TRUE

This one throws an error:

> data.frame(x = c(1, 1, 2), r = c(T, F, T)) %>% tbl_dt %>% filter(r)
Error in eval(expr, envir, enclos) : object 'r' not found

Both tbl_df and a base data.frame keep working just fine.

> data.frame(x = c(1, 1, 2), r = c(T, F, T)) %>% tbl_df %>% filter(r)
Source: local data frame [2 x 2]

  x    r
1 1 TRUE
2 2 TRUE

> data.frame(x = c(1, 1, 2), r = c(T, F, T)) %>% filter(r)
  x    r
1 1 TRUE
2 2 TRUE
> sessionInfo()
R version 3.1.1 Patched (2014-09-06 r66537)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Polish_Poland.1250  LC_CTYPE=Polish_Poland.1250    LC_MONETARY=Polish_Poland.1250
[4] LC_NUMERIC=C                   LC_TIME=Polish_Poland.1250    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] data.table_1.9.2 dplyr_0.2       

loaded via a namespace (and not attached):
[1] assertthat_0.1 magrittr_1.1.0 parallel_3.1.1 plyr_1.8.1     Rcpp_0.11.2    reshape2_1.4  
[7] stringr_0.6.2  tools_3.1.1   
@hadley hadley added the bug an unexpected problem or unintended behavior label Sep 11, 2014
@hadley hadley added this to the 0.3 milestone Sep 11, 2014
@romainfrancois
Copy link
Member

@hadley do you really want me to pick this up; This is data.table stuff for which I'm kind of clueless.

It looks like it happens in the eval call in filter.data.table

filter.data.table <- function(.data, ..., .env = parent.frame()) {
  expr <- and_expr(dots(...))
  call <- substitute(.data[expr, ])

  eval_env <- new.env(parent = .env)
  eval_env$.data <- .data

  eval(call, eval_env)
}

The generated call looks like : .data[r,] which does not look to work with data.table, as in:

> dt <- data.table( x = c(1, 1, 2), r = c(T, F, T))
> dt[r,]
Erreur dans eval(expr, envir, enclos) : objet 'r' introuvable

@hadley
Copy link
Member

hadley commented Sep 11, 2014

Ooops, no. I misread the message.

@hadley hadley modified the milestones: 0.3.1, 0.3 Sep 11, 2014
@hadley hadley assigned hadley and unassigned romainfrancois Sep 11, 2014
@hadley
Copy link
Member

hadley commented Nov 18, 2014

@arunsrinivasan is this a bug, or deliberate?

dt <- data.table( x = c(1, 1, 2), r = c(T, F, T))
dt[r, ]
# Error in eval(expr, envir, enclos) : object 'r' not found 
dt[r == T,]
#    x    r
# 1: 1 TRUE
# 2: 2 TRUE

Comparing a logical vector to TRUE is usually a redundant operation.

@arunsrinivasan
Copy link
Contributor

Expected. When i is symbol DT[i] looks for i in calling scope (for data.tables). DT[(r)] would be the way to go - until #697 is taken care of.

@hadley
Copy link
Member

hadley commented Nov 19, 2014

Fixed as part of 225f01b

@hadley hadley closed this as completed Nov 19, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants