juliasilge / widyr

Widen, process, and re-tidy a dataset
http://juliasilge.github.io/widyr/
Other
327 stars 29 forks source link

pairwise_count error #11

Closed chasec closed 2 years ago

chasec commented 7 years ago

I'm having trouble getting the example from ?pairwise_count to run:

dat <- data_frame(group = rep(1:5, each = 2),
                  letter = c("a", "b",
                             "a", "c",
                             "a", "c",
                             "b", "e",
                             "b", "f"))
pairwise_count(dat, letter, group)

Results in:

Error in distinct_impl(dist$data, dist$vars, dist$keep) : 
  unknown column 'row_col' 

Here's my session info:


R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

other attached packages:
[1] dplyr_0.5.0     purrr_0.2.2     readr_1.1.0     tidyr_0.6.1     tibble_1.2      ggplot2_2.2.1   tidyverse_1.1.1 widyr_0.1.0    

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.13      cellranger_1.1.0  compiler_3.4.2    plyr_1.8.4        tokenizers_0.1.4  forcats_0.2.0     tools_3.4.2       jsonlite_1.5      lubridate_1.7.1  
[10] gtable_0.2.0      nlme_3.1-131      lattice_0.20-35   rlang_0.1.2       Matrix_1.2-11     psych_1.7.8       DBI_0.7           yaml_2.1.14       parallel_3.4.2   
[19] haven_1.1.0       janeaustenr_0.1.5 xml2_1.1.1        stringr_1.2.0     httr_1.3.1        hms_0.3           grid_3.4.2        R6_2.2.2          readxl_1.0.0     
[28] foreign_0.8-69    reshape2_1.4.2    modelr_0.1.1      magrittr_1.5      SnowballC_0.5.1   scales_0.5.0      tidytext_0.1.4    rvest_0.3.2       assertthat_0.2.0 
[37] mnormt_1.5-5      colorspace_1.3-2  stringi_1.1.5     lazyeval_0.2.1    munsell_0.4.3     broom_0.4.2 
amrrs commented 7 years ago

Is it fixed? If not, can you update your dplyr to the latest?

Mine is dplyr_0.7.4 and it works fine.

juliasilge commented 7 years ago

I also cannot reproduce this:

library(widyr)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

dat <- data_frame(group = rep(1:5, each = 2),
                  letter = c("a", "b",
                             "a", "c",
                             "a", "c",
                             "b", "e",
                             "b", "f"))
pairwise_count(dat, letter, group)
#> # A tibble: 8 x 3
#>   item1 item2     n
#>   <chr> <chr> <dbl>
#> 1 b     a      1.00
#> 2 c     a      2.00
#> 3 a     b      1.00
#> 4 e     b      1.00
#> 5 f     b      1.00
#> 6 a     c      2.00
#> 7 b     e      1.00
#> 8 b     f      1.00

I would try updating to the latest versions of widyr and dplyr and check it out again.

jayjacobs commented 6 years ago

After updating to R 3.4.4, I was getting a similar warning from pairwise_count (warning from distinct()) , and reinstalling did not fix the error, I eventually got a bindrcpp error about "bindrcpp_RcppExport_validate" not being in bindrcpp, that led me to https://github.com/tidyverse/dplyr/issues/3079.

I fixed the warning by following the comment in the tidyverse issue by doing:

remove.packages(c("dplyr", "Rcpp", "bindr", "bindrcpp", "BH", "glue", "rlang")) and then of course: install.packages(c("dplyr", "Rcpp", "bindr", "bindrcpp", "BH", "glue", "rlang"))

Though I suspect just removing and installing "bindrcpp" may have fixed it.

johngoldin commented 6 years ago

I also get the error when I try to run the pairwise_count example code.

I tried

remove.packages(c("dplyr", "Rcpp", "bindr", "bindrcpp", "BH", "glue", "rlang")) and then of course: install.packages(c("dplyr", "Rcpp", "bindr", "bindrcpp", "BH", "glue", "rlang")).

as suggested by jayjacobs, but still got the error.

library(widyr)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
dat <- data_frame(group = rep(1:5, each = 2),
                  letter = c("a", "b",
                             "a", "c",
                             "a", "c",
                             "b", "e",
                             "b", "f"))

# count the number of times two letters appear together
pairwise_count(dat, letter, group)
#> Warning: Trying to compute distinct() for variables not found in the data:
#> - `row_col`, `column_col`
#> This is an error, but only a warning is raised for compatibility reasons.
#> The operation will return the input unchanged.
#> # A tibble: 8 x 3
#>   item1 item2     n
#>   <chr> <chr> <dbl>
#> 1 b     a         1
#> 2 c     a         2
#> 3 a     b         1
#> 4 e     b         1
#> 5 f     b         1
#> 6 a     c         2
#> 7 b     e         1
#> 8 b     f         1

Created on 2018-07-31 by the reprex package (v0.2.0).

Session info ``` r sessionInfo() #> R version 3.5.1 (2018-07-02) #> Platform: x86_64-apple-darwin15.6.0 (64-bit) #> Running under: macOS High Sierra 10.13.6 #> #> Matrix products: default #> BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib #> LAPACK: /Library/Frameworks/R.framework/Versions/3.5/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] bindrcpp_0.2.2 dplyr_0.7.6 widyr_0.1.1 #> #> loaded via a namespace (and not attached): #> [1] Rcpp_0.12.18 knitr_1.20 bindr_0.1.1 #> [4] magrittr_1.5 tidyselect_0.2.4 lattice_0.20-35 #> [7] R6_2.2.2 rlang_0.2.1 fansi_0.2.3 #> [10] stringr_1.3.1 tools_3.5.1 tidytext_0.1.9 #> [13] grid_3.5.1 nlme_3.1-137 broom_0.5.0 #> [16] utf8_1.1.4 cli_1.0.0 janeaustenr_0.1.5 #> [19] htmltools_0.3.6 yaml_2.1.19 rprojroot_1.3-2 #> [22] digest_0.6.15 assertthat_0.2.0 tibble_1.4.2 #> [25] crayon_1.3.4 Matrix_1.2-14 tidyr_0.8.1 #> [28] purrr_0.2.5 SnowballC_0.5.1 tokenizers_0.2.1 #> [31] glue_1.3.0 evaluate_0.11 rmarkdown_1.10 #> [34] stringi_1.2.4 compiler_3.5.1 pillar_1.3.0 #> [37] backports_1.1.2 pkgconfig_2.0.1 ```
johngoldin commented 6 years ago

Just tried the same code on my windows machine at work and got the same error.

johngoldin commented 6 years ago

I googled the error message and saw that it came from something in tidytext that was fixed in June. After I installed tidytext from GitHub. Now I have version of 0.1.9.900 in tidytext and the pairwise_count example works without an error message.

akastrin commented 4 years ago

It seems that the error still persits:

dat <- tibble(group = rep(1:5, each = 2),
                   letter = c("a", "b",
                              "a", "c",
                              "a", "c",
                              "b", "e",
                              "b", "f"))  
pairwise_count(dat, letter, group)
Error in `colnames<-`(`*tmp*`, value = c("item1", "item2", "value")) : 
  attempt to set 'colnames' on an object with less than two dimensions

Any idea what to do?

sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Manjaro Linux

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

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

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

other attached packages:
 [1] tidytext_0.2.4    remotes_2.1.1     forcats_0.5.0     stringr_1.4.0    
 [5] purrr_0.3.3       tibble_3.0.0      ggplot2_3.3.0     tidyverse_1.3.0  
 [9] tidyr_1.0.2       readr_1.3.1       widyr_0.1.3       dplyr_0.8.99.9002
[13] stringi_1.4.6    

loaded via a namespace (and not attached):
 [1] tidyselect_1.0.0  haven_2.2.0       lattice_0.20-38   colorspace_1.4-1 
 [5] vctrs_0.2.99.9011 generics_0.0.2    SnowballC_0.7.0   rlang_0.4.5.9000 
 [9] pillar_1.4.3      glue_1.4.0        withr_2.1.2       DBI_1.1.0        
[13] dbplyr_1.4.2      modelr_0.1.6      readxl_1.3.1      lifecycle_0.2.0  
[17] munsell_0.5.0     gtable_0.3.0      cellranger_1.1.0  rvest_0.3.5      
[21] curl_4.3          fansi_0.4.1       broom_0.5.3.9000  tokenizers_0.2.1 
[25] Rcpp_1.0.4.6      scales_1.1.0      backports_1.1.6   jsonlite_1.6.1   
[29] fs_1.4.1          hms_0.5.3         grid_3.6.3        cli_2.0.2        
[33] tools_3.6.3       magrittr_1.5      janeaustenr_0.1.5 crayon_1.3.4     
[37] pkgconfig_2.0.3   ellipsis_0.3.0    Matrix_1.2-18     xml2_1.3.1       
[41] reprex_0.3.0      lubridate_1.7.8   assertthat_0.2.1  httr_1.4.1       
[45] rstudioapi_0.11   R6_2.4.1          compiler_3.6.3   
swirvi commented 4 years ago

Have there been any updates to this error? I have been searching for a couple hours now and have not found a way to get this function example code to run without the same error mentioned above.

juliasilge commented 4 years ago

Have you tried installing the current GitHub version of widyr, and updating packages such as rlang and dplyr (with update.packages())?

devtools::install_github("dgrtwo/widyr")

I believe the one thing you should get right now is a warning about distinct_:

library(widyr)
library(tibble)
dat <- tibble(group = rep(1:5, each = 2),
                   letter = c("a", "b",
                              "a", "c",
                              "a", "c",
                              "b", "e",
                              "b", "f"))  
pairwise_count(dat, letter, group)
#> Warning: `distinct_()` is deprecated as of dplyr 0.7.0.
#> Please use `distinct()` instead.
#> See vignette('programming') for more help
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_warnings()` to see where this warning was generated.
#> # A tibble: 8 x 3
#>   item1 item2     n
#>   <chr> <chr> <dbl>
#> 1 b     a         1
#> 2 c     a         2
#> 3 a     b         1
#> 4 e     b         1
#> 5 f     b         1
#> 6 a     c         2
#> 7 b     e         1
#> 8 b     f         1

Created on 2020-07-15 by the reprex package (v0.3.0.9001)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.2 (2020-06-22) #> os macOS Mojave 10.14.6 #> system x86_64, darwin17.0 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/Denver #> date 2020-07-15 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0) #> backports 1.1.8 2020-06-17 [1] CRAN (R 4.0.0) #> broom 0.7.0 2020-07-09 [1] CRAN (R 4.0.0) #> cli 2.0.2 2020-02-28 [1] CRAN (R 4.0.0) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.0) #> digest 0.6.25 2020-02-23 [1] CRAN (R 4.0.0) #> dplyr 1.0.0 2020-05-29 [1] CRAN (R 4.0.0) #> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.0) #> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0) #> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.0) #> fs 1.4.2 2020-06-30 [1] CRAN (R 4.0.0) #> generics 0.0.2 2018-11-29 [1] CRAN (R 4.0.0) #> glue 1.4.1 2020-05-13 [1] CRAN (R 4.0.0) #> highr 0.8 2019-03-20 [1] CRAN (R 4.0.0) #> htmltools 0.5.0 2020-06-16 [1] CRAN (R 4.0.0) #> janeaustenr 0.1.5 2017-06-10 [1] CRAN (R 4.0.0) #> knitr 1.29 2020-06-23 [1] CRAN (R 4.0.0) #> lattice 0.20-41 2020-04-02 [1] CRAN (R 4.0.2) #> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.0) #> magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.0) #> Matrix 1.2-18 2019-11-27 [1] CRAN (R 4.0.2) #> pillar 1.4.6 2020-07-10 [1] CRAN (R 4.0.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.0) #> R6 2.4.1 2019-11-12 [1] CRAN (R 4.0.0) #> Rcpp 1.0.5 2020-07-06 [1] CRAN (R 4.0.0) #> reprex 0.3.0.9001 2020-06-08 [1] Github (tidyverse/reprex@d898823) #> rlang 0.4.7 2020-07-09 [1] CRAN (R 4.0.0) #> rmarkdown 2.3 2020-06-18 [1] CRAN (R 4.0.0) #> rstudioapi 0.11 2020-02-07 [1] CRAN (R 4.0.0) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.0) #> SnowballC 0.7.0 2020-04-01 [1] CRAN (R 4.0.0) #> stringi 1.4.6 2020-02-17 [1] CRAN (R 4.0.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.0) #> styler 1.3.2 2020-02-23 [1] CRAN (R 4.0.0) #> tibble * 3.0.3 2020-07-10 [1] CRAN (R 4.0.2) #> tidyr 1.1.0 2020-05-20 [1] CRAN (R 4.0.0) #> tidyselect 1.1.0 2020-05-11 [1] CRAN (R 4.0.0) #> tidytext 0.2.5 2020-07-11 [1] CRAN (R 4.0.0) #> tokenizers 0.2.1 2018-03-29 [1] CRAN (R 4.0.0) #> utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.0) #> vctrs 0.3.2 2020-07-15 [1] CRAN (R 4.0.2) #> widyr * 0.1.3 2020-07-15 [1] Github (dgrtwo/widyr@ee925e4) #> withr 2.2.0 2020-04-20 [1] CRAN (R 4.0.0) #> xfun 0.15 2020-06-21 [1] CRAN (R 4.0.0) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.0) #> #> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library ```
swirvi commented 4 years ago

Thank you! That was the issue! It was an outdated dplyr package. It is working now.

rentheduke commented 3 years ago

I'm still getting the same error. I've updated the packages and no luck. Any thoughts?

library(widyr)
library(tibble)
dat <- tibble(group = rep(1:5, each = 2),
                  ` letter = c("a", "b",`
                             ` "a", "c",`
                              "a", "c",
                              "b", "e",
                              "b", "f"))  
pairwise_count(dat, letter, group)

Result:

Error in `colnames<-`(`*tmp*`, value = c("item1", "item2", "value")) : attempt to set 'colnames' on an object with less than two dimensions
Session Info ``` package * version date lib source assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.3) backports 1.2.1 2020-12-09 [1] CRAN (R 4.0.3) broom 0.7.8 2021-06-24 [1] CRAN (R 4.0.5) cellranger 1.1.0 2016-07-27 [1] CRAN (R 4.0.3) cli 3.0.0 2021-06-30 [1] CRAN (R 4.0.5) crayon 1.4.1 2021-02-08 [1] CRAN (R 4.0.3) data.table 1.14.0 2021-02-21 [1] CRAN (R 4.0.5) DBI 1.1.1 2021-01-15 [1] CRAN (R 4.0.3) digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.3) dplyr 1.0.7 2021-06-18 [1] CRAN (R 4.0.5) ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.0.5) evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.3) fansi 0.4.2 2021-01-15 [1] CRAN (R 4.0.3) generics 0.1.0 2020-10-31 [1] CRAN (R 4.0.3) glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.3) htmltools 0.5.1.1 2021-01-22 [1] CRAN (R 4.0.3) janeaustenr 0.1.5 2017-06-10 [1] CRAN (R 4.0.4) knitr 1.33 2021-04-24 [1] CRAN (R 4.0.5) koRpus 0.13-8 2021-05-17 [1] CRAN (R 4.0.5) koRpus.lang.en 0.1-4 2020-10-24 [1] CRAN (R 4.0.5) lattice 0.20-41 2020-04-02 [1] CRAN (R 4.0.3) lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.0.5) magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.3) Matrix 1.2-18 2019-11-27 [1] CRAN (R 4.0.3) pillar 1.6.1 2021-05-16 [1] CRAN (R 4.0.5) pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.3) purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.3) R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.3) Rcpp 1.0.6 2021-01-15 [1] CRAN (R 4.0.3) readxl 1.3.1 2019-03-13 [1] CRAN (R 4.0.3) rlang 0.4.11 2021-04-30 [1] CRAN (R 4.0.5) rmarkdown 2.9 2021-06-15 [1] CRAN (R 4.0.5) rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.0.3) sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.3) SnowballC 0.7.0 2020-04-01 [1] CRAN (R 4.0.3) stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.3) stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.3) sylly 0.1-6 2020-09-20 [1] CRAN (R 4.0.5) sylly.en 0.1-3 2018-03-19 [1] CRAN (R 4.0.5) textstem 0.1.4 2018-04-09 [1] CRAN (R 4.0.5) tibble * 3.1.2 2021-05-16 [1] CRAN (R 4.0.5) tidyr 1.1.3 2021-03-03 [1] CRAN (R 4.0.5) tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.0.5) tidytext 0.3.1 2021-04-10 [1] CRAN (R 4.0.5) tokenizers 0.2.1 2018-03-29 [1] CRAN (R 4.0.4) utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.3) vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.0.5) widyr * 0.1.3 2021-07-22 [1] Github (dgrtwo/widyr@13b3b3c) withr 2.4.2 2021-04-18 [1] CRAN (R 4.0.5) xfun 0.24 2021-06-15 [1] CRAN (R 4.0.5) yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.3) ```
deleonmj commented 2 years ago

Hi! I'm getting the same error as @rentheduke with the same code. I've also updated all the packages. Any ideas on how else to resolve the error? Thank you!

juliasilge commented 2 years ago

This has now been fixed in the new widyr 0.1.5 that just went to CRAN:

library(tidyverse)
library(widyr)

dat <- data_frame(group = rep(1:5, each = 2),
                  letter = c("a", "b",
                             "a", "c",
                             "a", "c",
                             "b", "e",
                             "b", "f"))
#> Warning: `data_frame()` was deprecated in tibble 1.1.0.
#> Please use `tibble()` instead.
pairwise_count(dat, letter, group)
#> # A tibble: 8 × 3
#>   item1 item2     n
#>   <chr> <chr> <dbl>
#> 1 b     a         1
#> 2 c     a         2
#> 3 a     b         1
#> 4 e     b         1
#> 5 f     b         1
#> 6 a     c         2
#> 7 b     e         1
#> 8 b     f         1

Created on 2022-09-13 with reprex v2.0.2

Thanks! 🙌