Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign uprio loses "label" attributes if a "labels" attribute also exists when roundtripping to ".sav" and ".dta". #268
Comments
Can you check the version from github please? Thanks for the report! |
Hello Thomas Leeper, By the way, after updating sjlabelled::write_spss does not even export anymore. Maybe this will help narrow down the problem. Kind regards Here is my MWE: MWE# when there are value labels (attribute "labels"), the variable label (attribute "label") is lost in rio::export to SPSSrm(list=ls()) ValueLabels <- as.numeric(c(1:3)) test <- data.frame(NoValueLabels, ValueLabels ) attr(test$NoValueLabels, "label") <- "Variablelabel, but without Valuelabels" attr(test$ValueLabels, "labels") <- c("Valuelabel 1"=1, "Valuelabel 2"=2, "Valuelabel 3"=3) rio::export(test, "test.sav") str(test) compare test vs. reimportTest attribute "label":when there are value labels (attr "labels"), the variable labels (attr "label") is lost in rio::export to SPSS#sessionInfo() Here is my sessioninfo: R version 4.0.1 (2020-06-06) Matrix products: default locale: attached base packages: other attached packages: loaded via a namespace (and not attached): |
May be this helps. It seems to me that "haven" changed the way the attributes are set. When you write and read the data with haven we have the same effect for the MWE above. But if the labelling uses haven::labelled_spss the labels are kept (as long as you use haven::write_sav). Here is the extended MWE: rm(list=ls()) ValueLabels <- as.numeric(c(1:3)) test <- data.frame(NoValueLabels, ValueLabels, HavenLabels) attr(test$NoValueLabels, "label") <- "Variablelabel, but without Valuelabels" attr(test$ValueLabels, "labels") <- c("Valuelabel 1"=1, "Valuelabel 2"=2, "Valuelabel 3"=3) test$HavenLabels <- haven::labelled_spss(test$HavenLabels, labels=c("Valuelabel 1"=1, "Valuelabel 2"=2, "Valuelabel 3"=3), label = "Variable and Valuelabels with haven" ) rio::export(test, "test.sav") haven::write_sav(test, "testHaven.sav") str(test) |
Thanks - I'll try to get to this as soon as possible. |
rubenarslan commentedApr 22, 2020
•
edited
The title says it all. For some reason, rio doesn't write the variable label attribute to SPSS/Stata files, if there is also a "labels" attribute (value labels). This wasn't always the case, but I can't say what version introduced the bug.
Created on 2020-04-22 by the reprex package (v0.3.0)
Session info