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

read_spss loses value labels of some strings #422

Closed
beckerbenj opened this issue Jan 30, 2019 · 4 comments

Comments

@beckerbenj
Copy link

commented Jan 30, 2019

Value labels of string variables with width >= 9 in SPSS files are inconsistently imported via read_sav. The only alternative package importing the value labels I could find was the readspss package. I also tried foreign and memisc; both packages seem to omit the value labels for both variables.

spss_created.zip
Variable overview of the example data:

grafik

df_haven <- haven::read_sav(file = "spss_created.sav", user_na = TRUE)
attr(df_haven$x, "labels")
#> one 
#> "1"
attr(df_haven$y, "labels")
#> NULL

df_readspss <- readspss::read.sav("spss_created.sav", convert.factors = FALSE)
attr(df_readspss, "longlabel")
#> $x
#> one 
#> "1" 
#> 
#> $y
#> one 
#> "1"

Created on 2019-01-30 by the reprex package (v0.2.1)

I have tried creating the .sav files with SPSS Version 22 and 25, with both the bug occurs. When the .sav file is created with haven, the bug does not occur.

library(haven)
path <- tempfile()
df <- tibble::tibble(
  x = labelled_spss(c("a", "Width of9"), c(one = "1")),
  y = labelled_spss(c("a", "Width of9"), c(one = "1"))
)

write_sav(df, path)
df1 <- read_sav(path, user_na = TRUE)
attr(df$x, "labels")
#> one 
#> "1"
attr(df$y, "labels")
#> one 
#> "1"

attr(df1$x, "labels")
#> one 
#> "1"
attr(df1$y, "labels")
#> one 
#> "1"

Created on 2019-01-30 by the reprex package (v0.2.1)

@hadley

This comment has been minimized.

Copy link
Member

commented Feb 1, 2019

I see this with latest readstat. @evanmiller, I think this is one for you.

evanmiller added a commit to WizardMac/ReadStat that referenced this issue Feb 3, 2019

SAV: Store long value labels in a single record
A misunderstanding of the spec assumed that long value labels each got
their own record. Instead they are all stored in a single record.

Cf. tidyverse/haven#422
@evanmiller

This comment has been minimized.

Copy link
Contributor

commented Feb 3, 2019

Try WizardMac/ReadStat@93c46f2 (dev branch)

@hadley

This comment has been minimized.

Copy link
Member

commented Feb 3, 2019

LGTM:

df_haven <- haven::read_sav("~/Desktop/spss_created.sav", user_na = TRUE)
attr(df_haven$x, "labels")
#> one 
#> "1"
attr(df_haven$y, "labels")
#> one 
#> "1"

Created on 2019-02-03 by the reprex package (v0.2.1.9000)

@hadley hadley closed this in 54f3cea Feb 3, 2019

@lock

This comment has been minimized.

Copy link

commented Aug 2, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Aug 2, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.