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 unique.default(x, nmax = nmax): unique() applies only to vectors #5392

Closed
XiangyunHuang opened this issue May 24, 2022 · 7 comments · Fixed by #5393
Closed

Error in unique.default(x, nmax = nmax): unique() applies only to vectors #5392

XiangyunHuang opened this issue May 24, 2022 · 7 comments · Fixed by #5393

Comments

@XiangyunHuang
Copy link

do.call("rbind.data.frame", lapply(base::split(x = iris, ~Species), head))
#>               Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
#> setosa.1               5.1         3.5          1.4         0.2     setosa
#> setosa.2               4.9         3.0          1.4         0.2     setosa
#> setosa.3               4.7         3.2          1.3         0.2     setosa
#> setosa.4               4.6         3.1          1.5         0.2     setosa
#> setosa.5               5.0         3.6          1.4         0.2     setosa
#> setosa.6               5.4         3.9          1.7         0.4     setosa
#> versicolor.51          7.0         3.2          4.7         1.4 versicolor
#> versicolor.52          6.4         3.2          4.5         1.5 versicolor
#> versicolor.53          6.9         3.1          4.9         1.5 versicolor
#> versicolor.54          5.5         2.3          4.0         1.3 versicolor
#> versicolor.55          6.5         2.8          4.6         1.5 versicolor
#> versicolor.56          5.7         2.8          4.5         1.3 versicolor
#> virginica.101          6.3         3.3          6.0         2.5  virginica
#> virginica.102          5.8         2.7          5.1         1.9  virginica
#> virginica.103          7.1         3.0          5.9         2.1  virginica
#> virginica.104          6.3         2.9          5.6         1.8  virginica
#> virginica.105          6.5         3.0          5.8         2.2  virginica
#> virginica.106          7.6         3.0          6.6         2.1  virginica

library(data.table)

iris <- as.data.table(iris)

do.call("rbind.data.frame", lapply(base::split(x = iris, ~Species), head))
#> Error in unique.default(x, nmax = nmax): unique() applies only to vectors

sessionInfo()
#> R version 4.2.0 (2022-04-22)
#> Platform: x86_64-apple-darwin17.0 (64-bit)
#> Running under: macOS Big Sur/Monterey 10.16
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] data.table_1.14.2
#> 
#> loaded via a namespace (and not attached):
#>  [1] rstudioapi_0.13   knitr_1.39        magrittr_2.0.3    R.cache_0.15.0   
#>  [5] rlang_1.0.2       fastmap_1.1.0     fansi_1.0.3       stringr_1.4.0    
#>  [9] styler_1.7.0      highr_0.9         tools_4.2.0       xfun_0.31        
#> [13] R.oo_1.24.0       utf8_1.2.2        cli_3.3.0         withr_2.5.0      
#> [17] htmltools_0.5.2   ellipsis_0.3.2    yaml_2.3.5        digest_0.6.29    
#> [21] tibble_3.1.7      lifecycle_1.0.1   crayon_1.5.1      purrr_0.3.4      
#> [25] R.utils_2.11.0    vctrs_0.4.1       fs_1.5.2          glue_1.6.2       
#> [29] evaluate_0.15     rmarkdown_2.14    reprex_2.0.1      stringi_1.7.6    
#> [33] compiler_4.2.0    pillar_1.7.0      R.methodsS3_1.8.1 pkgconfig_2.0.3

Created on 2022-05-24 by the reprex package (v2.0.1)

@MichaelChirico
Copy link
Member

IIUC this is a request for is.formula(f) to work with data.table's split method

@XiangyunHuang
Copy link
Author

Yeah! Is it possible to support formula syntax in data.table?

@ben-schwen
Copy link
Member

@XiangyunHuang totally possible but not sure if wanted. Will work on a PR. (1-liner if we take over the eval from split.data.frame).

@MichaelChirico
Copy link
Member

at the very least we should fail more gracefully. but I don't see any problem with supporting this either for parity with data.frame.

@MichaelChirico
Copy link
Member

No wonder I had never heard of this before -- it's a very new base R feature!

r-devel/r-svn@82b4382

@YuyanCao
Copy link

Hi, did you work it out? I also met this problem when using R

@jangorecki
Copy link
Member

Try out linked PR and tell us if it works for you.

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

Successfully merging a pull request may close this issue.

5 participants