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 .subset(x, j) : invalid subscript type 'language' when using mutate_all #51

Closed
adamryczkowski opened this issue Jun 17, 2017 · 8 comments

Comments

@adamryczkowski
Copy link

library(data.table)
library(dtplyr)
library(dplyr)
dt <- data.table(a=1:10, b=1:10, c=1:10)
dt %>%  mutate_all(as.integer)
# Error in .subset(x, j) : invalid subscript type 'language'

When we remove data.table nature of the dt, everything works:

library(data.table)
library(dtplyr)
library(dplyr)
dt <- data.table(a=1:10, b=1:10, c=1:10)
df <- as.data.frame(dt)
df %>% mutate_all(as.integer)

#     a  b  c
# 1   1  1  1
# 2   2  2  2
# 3   3  3  3
# 4   4  4  4
# 5   5  5  5
# 6   6  6  6
# 7   7  7  7
# 8   8  8  8
# 9   9  9  9
# 10 10 10 10
> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.2 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=pl_PL.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=pl_PL.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=pl_PL.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=pl_PL.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] bindrcpp_0.1      data.table_1.10.4 dplyr_0.7.0       dtplyr_0.0.2.9000

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.11     digest_0.6.12    withr_1.0.2      assertthat_0.2.0 R6_2.2.1         git2r_0.18.0     magrittr_1.5     httr_1.2.1       rlang_0.1.1     
[10] lazyeval_0.2.0   curl_2.6         devtools_1.13.2  tools_3.4.0      glue_1.1.0       compiler_3.4.0   memoise_1.1.0    bindr_0.1        tibble_1.3.3    
@MarkusBonsch
Copy link

Same for transmute with dplyr 0.7.1 under R 3.3.3:

library(data.table)
library(dplyr)
library(dtplyr)

test <- data.table(a=1, b=2)
transmute(test, c = 1)
# Error in .subset(x, j) : invalid subscript type 'language'
> sessionInfo()
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

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

other attached packages:
 [1] dtplyr_0.0.2         dplyr_0.7.1          data.table_1.10.4    RevoUtilsMath_10.0.0 RevoUtils_10.0.3    
 [6] RevoMods_11.0.0      MicrosoftML_1.3.0    mrsdeploy_1.1.0      RevoScaleR_9.1.0     lattice_0.20-34     
[11] rpart_4.1-10        

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.11           codetools_0.2-15       CompatibilityAPI_1.1.0 assertthat_0.1         foreach_1.4.3         
 [6] grid_3.3.3             R6_2.2.0               jsonlite_1.3           magrittr_1.5           rlang_0.1.1           
[11] lazyeval_0.2.0         curl_2.3               bindrcpp_0.2           iterators_1.0.8        tools_3.3.3           
[16] glue_1.1.1             pkgconfig_2.0.1        bindr_0.1              tibble_1.3.3           mrupdate_1.0.1     

@jreades
Copy link

jreades commented Jun 28, 2017

I've also encountered this (as part of a long pipeline, and my example wouldn't meaningfully add to this) and the workaround posted above also worked (as.data.frame(dt)).

> sessionInfo()
R version 3.3.3 (2017-03-06)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.5

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

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

other attached packages:
 [1] Hmisc_4.0-3     ggplot2_2.2.1   Formula_1.2-1   survival_2.40-1 lattice_0.20-34 zoo_1.8-0       dtplyr_0.0.2    bindrcpp_0.2    sf_0.5-2        reshape2_1.4.2 
[11] dplyr_0.7.1     plyr_1.8.4     

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.11        RColorBrewer_1.1-2  bindr_0.1           base64enc_0.1-3     tools_3.3.3         digest_0.6.9        rpart_4.1-10        checkmate_1.8.2    
 [9] htmlTable_1.9       tibble_1.3.3        gtable_0.2.0        pkgconfig_2.0.1     rlang_0.1.1         Matrix_1.2-8        DBI_0.7             gridExtra_2.2.1    
[17] knitr_1.13          cluster_2.0.5       stringr_1.0.0       htmlwidgets_0.8     nnet_7.3-12         grid_3.3.3          glue_1.1.1          data.table_1.9.6   
[25] R6_2.1.2            foreign_0.8-67      latticeExtra_0.6-28 udunits2_0.13       magrittr_1.5        htmltools_0.3.6     backports_1.1.0     scales_0.4.1       
[33] units_0.4-5         splines_3.3.3       assertthat_0.1      colorspace_1.2-6    stringi_1.1.1       acepack_1.4.1       lazyeval_0.2.0      munsell_0.4.3      
[41] chron_2.3-47 

@Feakster
Copy link

The same problem is present for mutate_at():

Error in .subset(x, j) : invalid subscript type 'language'

@BabaYara
Copy link

BabaYara commented Jul 7, 2017

One work around is to wrap your object in "as_tibble()" function to drop the data.table class attributes from the object but retain the benefits of a tibble object.

@MarkusBonsch
Copy link

What you essentially say is: don't use data.table if working with dplyr.
I personally will rather stop using dplyr if this problem doesn't get any attention.

@lionel-
Copy link
Member

lionel- commented Jul 10, 2017

We may try to get an update during the summer, I'll talk to Hadley about dtplyr.

@MarkusBonsch
Copy link

MarkusBonsch commented Jul 10, 2017

Thank you.
It would also be good to have a statement about the future strategy:
is it envisaged to maintain data.table support for dplyr through dtplyr?
At the moment, this doesn't seem to be the case.

@otoomet
Copy link

otoomet commented Sep 19, 2017

A similar issue:

> a <- data.table(a=1:2, b=c("a", "b"))
> dplyr::group_by_(a, "b") %>% summarize(m=mean(a))
Error in .subset(x, j) : invalid subscript type 'language'

if wrapping a into as_tibble(), or if using NSE, it works as expected.

> packageVersion("dplyr")
[1] ‘0.7.3’
> packageVersion("dtplyr")
[1] ‘0.0.2’

@hadley hadley closed this as completed in addd7ff May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants