tidyverse / dplyr

dplyr: A grammar of data manipulation
https://dplyr.tidyverse.org/
Other
4.78k stars 2.12k forks source link

Possible environment evaluating issues with data.table 1.9.4 #839

Closed vzemlys closed 9 years ago

vzemlys commented 9 years ago

Here is the following code:

aa<-data.table(a=letters[1:10],b=1:10)
fun<-function(x,y) y[y==x]
fun("a", aa$a)
aa %>%  filter(a %in% fun("a",a))
aa %>% data.frame %>%  filter(a %in% fun("a",a))

The fourth line produces an error:

Erreur dans fun("a", a) : objet 'a' introuvable

The fifth line does not produce the error. This behaviour appeared with data.table 1.9.4, it worked fine with version 1.9.2. This is my hypothesis though.

Here is the output of sessionInfo():

R version 3.1.1 (2014-07-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

locale:
[1] fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/fr_FR.UTF-8

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

other attached packages:
[1] data.table_1.9.4 dplyr_0.3.0.2    urca_1.2-8       mvtnorm_1.0-0    effects_3.0-2   

loaded via a namespace (and not attached):
 [1] assertthat_0.1.0.99 chron_2.3-45        colorspace_1.2-4    DBI_0.3.1           grid_3.1.1          lattice_0.20-29     lazyeval_0.1.9     
 [8] lme4_1.1-7          magrittr_1.5        MASS_7.3-33         Matrix_1.1-4        minqa_1.2.3         nlme_3.1-117        nloptr_1.0.0       
[15] nnet_7.3-8          parallel_3.1.1      pbkrtest_0.4-2      plyr_1.8.1          Rcpp_0.11.2         reshape2_1.4        splines_3.1.1      
[22] stringr_0.6.2       tools_3.1.1 
vzemlys commented 9 years ago

I had a similar issue, when in dplyr pipe inside a function, function arguments were not respected when using data.table arguments. I did not manage (or was too busy) to write the reproducible example, so I'm just mentioning it here, it might be similar bug.

hadley commented 9 years ago

I fixed a few of these problems in the dev version. Could you try it out please?

vzemlys commented 9 years ago

With the dev version everything works (both issues are solved). Thanks! Posting sessionInfo just in case:

R version 3.1.1 (2014-07-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

locale:
[1] fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/C

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

other attached packages:
[1] lazyeval_0.1.9.9001 magrittr_1.5        tidyr_0.2.0        
[4] dplyr_0.3.0.9000    data.table_1.9.4   

loaded via a namespace (and not attached):
 [1] assertthat_0.1.0.99 chron_2.3-45        compiler_3.1.1     
 [4] DBI_0.3.1           parallel_3.1.1      plyr_1.8.1         
 [7] Rcpp_0.11.3         reshape2_1.4        stringi_0.3-1      
[10] stringr_0.6.2       tools_3.1.1