nacnudus / unpivotr

Unpivot complex and irregular data layouts in R
https://nacnudus.github.io/unpivotr/
Other
185 stars 19 forks source link

Error using behead with up-left: no applicable method for 'inner_join' #38

Closed stveep closed 4 years ago

stveep commented 4 years ago

Hi,

Thanks for this great package. I am getting an error using behead() with the "up-left" option. My data looked ok so I tried to reproduce the example in the book and this failed with the same error:

Error in UseMethod("inner_join"): no applicable method for 'inner_join' applied to an object of class "c('integer', 'numeric')"

I have tried to investigate further but not got very far. It runs successfully using "up", giving every other row in the gender column as NA as expected. Similarly, using "left" succeeds but "up-left" fails with the same error.

Any help or pointers appreciated! Example below:

https://nacnudus.github.io/spreadsheet-munging-strategies/pivot-simple.html

library(tidyverse)
library(readxl)
library(unpivotr)
library(tidyxl)

print(sessionInfo())
## R version 3.6.0 (2019-04-26)
## Platform: x86_64-apple-darwin16.7.0 (64-bit)
## Running under: macOS High Sierra 10.13.6
##
## Matrix products: default
## BLAS/LAPACK: /usr/local/Cellar/openblas/0.3.6_1/lib/libopenblasp-r0.3.6.dylib
##
## 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] knitr_1.22      tidyxl_1.0.6    unpivotr_0.6.0  readxl_1.3.1
##  [5] forcats_0.4.0   stringr_1.4.0   dplyr_0.8.3     purrr_0.3.2
##  [9] readr_1.3.1     tidyr_0.8.3     tibble_2.1.1    ggplot2_3.1.1
## [13] tidyverse_1.2.1
##
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.1       pillar_1.3.1     compiler_3.6.0   cellranger_1.1.0
##  [5] plyr_1.8.4       tools_3.6.0      evaluate_0.13    jsonlite_1.6
##  [9] lubridate_1.7.4  gtable_0.3.0     nlme_3.1-139     lattice_0.20-38
## [13] pkgconfig_2.0.2  rlang_0.4.0      cli_1.1.0        rstudioapi_0.10
## [17] xfun_0.6         haven_2.1.0      withr_2.1.2      xml2_1.2.0
## [21] httr_1.4.0       generics_0.0.2   hms_0.4.2        grid_3.6.0
## [25] tidyselect_0.2.5 glue_1.3.1       R6_2.4.0         fansi_0.4.0
## [29] modelr_0.1.4     magrittr_1.5     backports_1.1.4  scales_1.0.0
## [33] rvest_0.3.3      assertthat_0.2.1 colorspace_1.4-1 utf8_1.1.4
## [37] stringi_1.4.3    lazyeval_0.2.2   munsell_0.5.0    broom_0.5.2
## [41] markdown_0.9     crayon_1.3.4
path <- system.file("extdata", "worked-examples.xlsx", package = "unpivotr")
testdata <- xlsx_cells(path, sheets = "pivot-annotations") %>%
        dplyr::filter(col >= 4, !is_blank) %>%
        select(row, col, data_type, character, numeric)

testdata %>% behead("up-left", gender)
## Error in UseMethod("inner_join"): no applicable method for 'inner_join' applied to an object of class "c('integer', 'numeric')"
testdata %>% behead("up", gender)
## # A tibble: 20 x 6
##      row   col data_type character numeric gender
##    <int> <int> <chr>     <chr>       <dbl> <chr>
##  1     3     4 character Matilda        NA Female
##  2     3     5 character Olivia         NA <NA>
##  3     3     6 character Nicholas       NA Male
##  4     3     7 character Paul           NA <NA>
##  5     4     4 numeric   <NA>            1 Female
##  6     4     5 numeric   <NA>            2 <NA>
##  7     4     6 numeric   <NA>            3 Male
[...]
nacnudus commented 4 years ago

Please can you try with the latest versions of dplyr and vctrs?

stveep commented 4 years ago

I updated vctrs (to 0.3.1, and rlang to 0.4.6) and it didn't work. After dplyr upgrade on top of this (v1.0.0) there was the same issue with a slightly more informative error message:

## Error: Problem with `filter()` input `..1`.
## ✖ no applicable method for 'inner_join' applied to an object of class "c('integer', 'numeric')"
## ℹ Input `..1` is `purrr::map_lgl(cells, contains_corner, corners)`.

However, after a full tidyverse upgrade it does work. Sorry I can't pin down which package was responsible but here is the environment that it works in, in case that helps if it comes up in future.

## R version 3.6.0 (2019-04-26)
## Platform: x86_64-apple-darwin16.7.0 (64-bit)
## Running under: macOS High Sierra 10.13.6
##  
## Matrix products: default
## BLAS/LAPACK: /usr/local/Cellar/openblas/0.3.6_1/lib/libopenblasp-r0.3.6.dylib
## 
## 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] tidyxl_1.0.6    unpivotr_0.6.0  readxl_1.3.1    forcats_0.4.0
##  [5] stringr_1.4.0   dplyr_1.0.0     purrr_0.3.4     readr_1.3.1
##  [9] tidyr_1.1.0     tibble_3.0.1    ggplot2_3.3.1   tidyverse_1.3.0
## [13] knitr_1.22
##
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.1       cellranger_1.1.0 pillar_1.4.4     compiler_3.6.0
##  [5] dbplyr_1.4.4     tools_3.6.0      lubridate_1.7.4  jsonlite_1.6
##  [9] evaluate_0.13    lifecycle_0.2.0  nlme_3.1-139     gtable_0.3.0
## [13] lattice_0.20-38  pkgconfig_2.0.2  rlang_0.4.6      reprex_0.3.0
## [17] cli_1.1.0        rstudioapi_0.10  DBI_1.0.0        haven_2.3.1
## [21] xfun_0.6         withr_2.1.2      xml2_1.3.2       httr_1.4.1
## [25] fs_1.3.1         generics_0.0.2   vctrs_0.3.1      hms_0.5.3
## [29] grid_3.6.0       tidyselect_1.1.0 glue_1.4.1       R6_2.4.0
## [33] modelr_0.1.8     blob_1.2.1       magrittr_1.5     backports_1.1.4
## [37] scales_1.0.0     ellipsis_0.3.1   rvest_0.3.5      assertthat_0.2.1
## [41] colorspace_1.4-1 stringi_1.4.3    munsell_0.5.0    broom_0.5.2
## [45] crayon_1.3.4

Thanks for your help!