clashncruz
clashncruz

Reputation: 21

ggstatsplot grouped_* function: Error in unique.default(x, nmax = nmax) : unique() applies only to vectors

I have seen this question asked by a number of people with different issues, but I have not found a response that fixes my problem.

I am having a problem with the following error when executing any of the grouped_* commands in ggstatsplot.

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

I have tried reinstalling R, reinstalling RStudio, and reinstalling all packages. I have also brought this up to the developer of ggstatsplot, but he said he cannot reproduce my error. I expect ggstatsplot to produce grouped plots based on the grouping variable. Instead, I receive the error above.

Here is a reprex with my sessionInfo and the traceback of the problem I am encountering.

If anyone has any idea what is going on here I would greatly appreciate it. Thank you.

Reprex with sessionInfo:

library(ggstatsplot)
#> You can cite this package as:
#>      Patil, I. (2021). Visualizations with statistical details: The 'ggstatsplot' approach.
#>      Journal of Open Source Software, 6(61), 3167, doi:10.21105/joss.03167

# Error in ggstatsplot grouping function

grouped_ggscatterstats(data = movies_long,
                       x = budget,
                       y = rating,    
                       grouping.var = genre)

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

Created on 2023-02-07 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.0.3 (2020-10-10)
#>  os       Ubuntu 20.04.5 LTS
#>  system   x86_64, linux-gnu
#>  ui       X11
#>  language en_CA:en
#>  collate  en_CA.UTF-8
#>  ctype    en_CA.UTF-8
#>  tz       America/Edmonton
#>  date     2023-02-07
#>  pandoc   2.19.2 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package          * version    date (UTC) lib source
#>  BayesFactor        0.9.12-4.4 2022-07-05 [1] CRAN (R 4.0.3)
#>  bayestestR         0.13.0     2022-09-18 [1] CRAN (R 4.0.3)
#>  cli                3.6.0      2023-01-09 [1] CRAN (R 4.0.3)
#>  coda               0.19-4     2020-09-30 [1] CRAN (R 4.0.3)
#>  codetools          0.2-18     2020-11-04 [4] CRAN (R 4.0.3)
#>  colorspace         2.1-0      2023-01-23 [1] CRAN (R 4.0.3)
#>  correlation        0.8.3      2022-10-09 [1] CRAN (R 4.0.3)
#>  curl               5.0.0      2023-01-12 [1] CRAN (R 4.0.3)
#>  datawizard         0.6.5      2022-12-14 [1] CRAN (R 4.0.3)
#>  digest             0.6.31     2022-12-11 [1] CRAN (R 4.0.3)
#>  dplyr              1.1.0      2023-01-29 [1] CRAN (R 4.0.3)
#>  effectsize         0.8.3      2023-01-28 [1] CRAN (R 4.0.3)
#>  emmeans            1.7.3      2022-03-27 [1] CRAN (R 4.0.3)
#>  estimability       1.4.1      2022-08-05 [1] CRAN (R 4.0.3)
#>  evaluate           0.20       2023-01-17 [1] CRAN (R 4.0.3)
#>  fansi              1.0.4      2023-01-22 [1] CRAN (R 4.0.3)
#>  farver             2.1.1      2022-07-06 [1] CRAN (R 4.0.3)
#>  fastmap            1.1.0      2021-01-25 [1] CRAN (R 4.0.3)
#>  fs                 1.6.1      2023-02-06 [1] CRAN (R 4.0.3)
#>  generics           0.1.3      2022-07-05 [1] CRAN (R 4.0.3)
#>  ggplot2            3.4.0      2022-11-04 [1] CRAN (R 4.0.3)
#>  ggside             0.2.2      2022-12-04 [1] CRAN (R 4.0.3)
#>  ggstatsplot      * 0.10.0     2022-11-27 [1] CRAN (R 4.0.3)
#>  glue               1.6.2      2022-02-24 [1] CRAN (R 4.0.3)
#>  gtable             0.3.1      2022-09-01 [1] CRAN (R 4.0.3)
#>  highr              0.10       2022-12-22 [1] CRAN (R 4.0.3)
#>  htmltools          0.5.4      2022-12-07 [1] CRAN (R 4.0.3)
#>  httr               1.4.4      2022-08-17 [1] CRAN (R 4.0.3)
#>  insight            0.19.0     2023-01-30 [1] CRAN (R 4.0.3)
#>  knitr              1.42       2023-01-25 [1] CRAN (R 4.0.3)
#>  labeling           0.4.2      2020-10-20 [1] CRAN (R 4.0.3)
#>  lattice            0.20-45    2021-09-22 [4] CRAN (R 4.1.1)
#>  lifecycle          1.0.3      2022-10-07 [1] CRAN (R 4.0.3)
#>  magrittr           2.0.3      2022-03-30 [1] CRAN (R 4.0.3)
#>  MASS               7.3-58.1   2022-08-03 [4] CRAN (R 4.2.1)
#>  Matrix             1.5-3      2022-11-11 [1] CRAN (R 4.0.3)
#>  MatrixModels       0.5-1      2022-09-11 [1] CRAN (R 4.0.3)
#>  mgcv               1.8-41     2022-10-21 [4] CRAN (R 4.2.1)
#>  mime               0.12       2021-09-28 [1] CRAN (R 4.0.3)
#>  multcomp           1.4-20     2022-08-07 [1] CRAN (R 4.0.3)
#>  munsell            0.5.0      2018-06-12 [1] CRAN (R 4.0.2)
#>  mvtnorm            1.1-3      2021-10-08 [1] CRAN (R 4.0.3)
#>  nlme               3.1-149    2020-08-23 [4] CRAN (R 4.0.2)
#>  paletteer          1.5.0      2022-10-19 [1] CRAN (R 4.0.3)
#>  parameters         0.20.2     2023-01-27 [1] CRAN (R 4.0.3)
#>  patchwork          1.1.2      2022-08-19 [1] CRAN (R 4.0.3)
#>  pbapply            1.7-0      2023-01-13 [1] CRAN (R 4.0.3)
#>  performance        0.10.2     2023-01-12 [1] CRAN (R 4.0.3)
#>  pillar             1.8.1      2022-08-19 [1] CRAN (R 4.0.3)
#>  pkgconfig          2.0.3      2019-09-22 [1] CRAN (R 4.0.2)
#>  purrr              1.0.1      2023-01-10 [1] CRAN (R 4.0.3)
#>  R.cache            0.16.0     2022-07-21 [1] CRAN (R 4.0.3)
#>  R.methodsS3        1.8.2      2022-06-13 [1] CRAN (R 4.0.3)
#>  R.oo               1.25.0     2022-06-12 [1] CRAN (R 4.0.3)
#>  R.utils            2.12.2     2022-11-11 [1] CRAN (R 4.0.3)
#>  R6                 2.5.1      2021-08-19 [1] CRAN (R 4.0.3)
#>  Rcpp               1.0.10     2023-01-22 [1] CRAN (R 4.0.3)
#>  rematch2           2.1.2      2020-05-01 [1] CRAN (R 4.0.2)
#>  reprex             2.0.2      2022-08-17 [1] CRAN (R 4.0.3)
#>  rlang              1.0.6      2022-09-24 [1] CRAN (R 4.0.3)
#>  rmarkdown          2.20       2023-01-19 [1] CRAN (R 4.0.3)
#>  rstudioapi         0.14       2022-08-22 [1] CRAN (R 4.0.3)
#>  sandwich           3.0-2      2022-06-15 [1] CRAN (R 4.0.3)
#>  scales             1.2.1      2022-08-20 [1] CRAN (R 4.0.3)
#>  sessioninfo        1.2.2      2021-12-06 [1] CRAN (R 4.0.3)
#>  statsExpressions   1.4.0      2023-01-14 [1] CRAN (R 4.0.3)
#>  stringi            1.7.12     2023-01-11 [1] CRAN (R 4.0.3)
#>  stringr            1.5.0      2022-12-02 [1] CRAN (R 4.0.3)
#>  styler             1.9.0      2023-01-15 [1] CRAN (R 4.0.3)
#>  survival           3.4-0      2022-08-09 [4] CRAN (R 4.2.1)
#>  TH.data            1.1-1      2022-04-26 [1] CRAN (R 4.0.3)
#>  tibble             3.1.8      2022-07-22 [1] CRAN (R 4.0.3)
#>  tidyr              1.3.0      2023-01-24 [1] CRAN (R 4.0.3)
#>  tidyselect         1.2.0      2022-10-10 [1] CRAN (R 4.0.3)
#>  utf8               1.2.3      2023-01-31 [1] CRAN (R 4.0.3)
#>  vctrs              0.5.2      2023-01-23 [1] CRAN (R 4.0.3)
#>  withr              2.5.0      2022-03-03 [1] CRAN (R 4.0.3)
#>  xfun               0.37       2023-01-31 [1] CRAN (R 4.0.3)
#>  xml2               1.3.3      2021-11-30 [1] CRAN (R 4.0.3)
#>  xtable             1.8-4      2019-04-21 [1] CRAN (R 4.0.2)
#>  yaml               2.3.7      2023-01-23 [1] CRAN (R 4.0.3)
#>  zeallot            0.1.0      2018-01-28 [1] CRAN (R 4.0.3)
#>  zoo                1.8-11     2022-09-17 [1] CRAN (R 4.0.3)
#> 
#>  [1] /media/user/4B/R/x86_64-pc-linux-gnu-library/4.0
#>  [2] /usr/local/lib/R/site-library
#>  [3] /usr/lib/R/site-library
#>  [4] /usr/lib/R/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Traceback:

13: unique.default(x, nmax = nmax)
12: unique(x, nmax = nmax)
11: factor(x)
10: as.factor(f)
9: split.default(x = seq_len(nrow(x)), f = f, drop = drop, ...)
8: split(x = seq_len(nrow(x)), f = f, drop = drop, ...)
7: lapply(split(x = seq_len(nrow(x)), f = f, drop = drop, ...), 
       function(ind) x[ind, , drop = FALSE])
6: split.data.frame(., f = new_formula(NULL, enquo(grouping.var)), 
       drop = TRUE)
5: split(., f = new_formula(NULL, enquo(grouping.var)), drop = TRUE)
4: data %>% split(f = new_formula(NULL, enquo(grouping.var)), drop = TRUE)
3: .grouped_list(., {
       {
           grouping.var
       }
   })
2: data %<>% .grouped_list({
       {
           grouping.var
       }
   })
1: grouped_ggscatterstats(movies_long, budget, rating, grouping.var = genre)

Created on 2023-02-08 with reprex v2.0.2

Upvotes: 1

Views: 74

Answers (1)

clashncruz
clashncruz

Reputation: 21

Yes, I think this was the issue @Phil and @Behnam Hedayat. I tried reinstalling RStudio, I tried updating RStudio, I tried different versions of ggstatsplot to no avail. Finally, I decided to try to upgrade my version of Ubuntu, which did not work due to other issues, but at least it did seem to catch some new updates to the r-base and a few other libraries I could see, I think that solved the issue because the grouped_* commands are now working as they should.

During this upgrade process R updated to R v4.2.2 as @Phil and @Behnam Hedayat suggested. Thank you both for your help.

For anyone that might have this problem in the future, the commands I ran in terminal were the following and I found them here:

sudo apt update

sudo apt upgrade && sudo apt dist-upgrade

sudo update-manager -d

Upvotes: 1

Related Questions