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

Issue with rec() else=copy not passing old labels #152

Open
aito123 opened this issue Jun 26, 2022 · 0 comments
Open

Issue with rec() else=copy not passing old labels #152

aito123 opened this issue Jun 26, 2022 · 0 comments

Comments

@aito123
Copy link

aito123 commented Jun 26, 2022

Hello active user of sjmic really cool package (sjverse in general).

Problem: while recoding and labelling a variable i saw that my old labels weren't been passed by else=copy argument when i added new labels. Here the reprex:

#vector using dput() function
data<-structure(c(1, 0, 0, 0, 0, 0), label = "¿La municipalidad realizó procedimiento administrativo de Licencia de edificación para viviendas de hasta 5 pisos o 3000 m² ?", format.spss = "F12.0", display_width = 12L, labels = c(Si = 1, 
No = 2), class = c("haven_labelled", "vctrs_vctr", "double"))

#(1) error not passing old labels when "adding" another
as.data.frame(data) %>% mutate( across(1, ~as_labelled(rec(., rec = '2=0[No];else=copy'))), ) %>% pull(1)
# <labelled<double>[6]>: ¿La municipalidad realizó procedimiento administrativo de Licencia de edificación para viviendas de hasta 5 pisos o 3000 m² ?
# [1] 1 0 0 0 0 0
# 
# Labels:
#  value label
#      0    No

#(2) desired result passing old labels
as.data.frame(data) %>% mutate( across(1, ~as_labelled(rec(., rec = '2=0;else=copy'))), ) %>% pull(1)
# <labelled<double>[6]>: ¿La municipalidad realizó procedimiento administrativo de Licencia de edificación para viviendas de hasta 5 pisos o 3000 m² ?
# [1] 1 0 0 0 0 0
# 
# Labels:
#  value label
#      0    No
#      1    Si

I think the behavior in (2) desired result passing old labels should also work in scenario (1) error not passing old labels when "adding another. In conclusion, it shouldn't drop labels 1 Si because i'm specifying that i want else=copy.

Let me know if its possible to fx this, thanks for the attention.
Regards

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

No branches or pull requests

1 participant