Skip to content

write_sav() fails to set missing values #596

@dusadrian

Description

@dusadrian

Information about missing values is lost, roundtrip reprex below

library(haven)
library(tibble)
test <- tibble(A = labelled_spss(1:10, c(Good = 1, Bad = 8, DK = 9, NR = 10), na_values = c(9, 10)))
test$A
# <labelled_spss<integer>[10]>
#  [1]  1  2  3  4  5  6  7  8  9 10
# Missing values: 9, 10

# Labels:
#  value label
#      1  Good
#      8   Bad
#      9    DK
#     10    NR

write_sav(test, "test.sav")

testback <- read_sav("test.sav")
testback$A
# <labelled<double>[10]>
#  [1]  1  2  3  4  5  6  7  8  9 10

# Labels:
#  value label
#      1  Good
#      8   Bad
#      9    DK
#     10    NR

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions