tidyverse / haven

Read SPSS, Stata and SAS files from R
https://haven.tidyverse.org
Other
423 stars 115 forks source link

bind_rows of data frames with haven_labelled variables fails #758

Open sjkiss opened 3 months ago

sjkiss commented 3 months ago

I have a package that stores a number of survey datasets with recoded data in them. The script below installs the package and tries to construct a tabular dataset from the various datasets. It was working for me up until recently. However, now it returns an error

Error inbind_rows(): ! Can't combine..1$male<haven_labelled> and..2$male<haven_labelled>. ✖ Some attributes are incompatible. ℹ The author of the class should implement vctrs methods.

This is a stripped down version of the code and it reproduces the error.

It was working for me earlier.

library(tidyverse)
remotes::install_github("sjkiss/cesdata2")
#> Using GitHub PAT from the git credential store.
#> Skipping install of 'cesdata2' from a github remote, the SHA1 (4bf65d7e) has not changed since last install.
#>   Use `force = TRUE` to force installation
library(cesdata2)
# List data frames
ces.list<-list(ces84, ces88, ces93, ces97, ces00, ces15phone, ces15web, ces19phone, ces19web, ces21)
#Provide names for list
names(ces.list)<-c( 1984, 1988, 1993, 1997, 2000, "2015 Phone", "2015 Web","2019 Phone", "2019 Web", 2021)
#Common variables to be selected

common_vars<-c('male',
               'sector', 
               'occupation', 'vote')

ces.list %>% 
  map(., select, any_of(common_vars))%>%
  #bind_rows smushes all the data frames together, and creates a variable called election
  bind_rows()->ces
#> Error in `bind_rows()`:
#> ! Can't combine `..1$male` <haven_labelled> and `..2$male` <haven_labelled>.
#> ✖ Some attributes are incompatible.
#> ℹ The author of the class should implement vctrs methods.
#> ℹ See <https://vctrs.r-lib.org/reference/faq-error-incompatible-attributes.html>.

Created on 2024-06-19 with reprex v2.1.0

sjkiss commented 3 months ago

Reverting to haven package 2.3.1 works. Note the potential similarity with this issue

sjkiss commented 3 months ago

Correction: It does not. I don't understand what is going on.

gorcha commented 2 months ago

Hi @sjkiss, I suspect this is a change in the vctrs package - could you please let me know what version of vctrs you have installed?