Skip to contents

The read_sav_gesis() function is a wrapper with haven::read_sav, declared:as.declared, and dataset::dublincore_add.

ZA5933 <- read_sav_gesis(file = system.file("extdata", "ZA5933_sample.sav", 
                                            package = "eurobarometer"))

The read_sav_gesis read in the file into declared class.

demography_vars <- get_demography_schema() 

Let us convert any variables where labelling plays no role to a simpler class. In this case, we will convert the id variable to a character vector, and the d11 (AGE EXACT) variable into a numeric.

demography <-ZA5933 %>%
  select( any_of( demography_vars$var_name_orig )) %>%
  mutate ( ## convert to numeric with keeping var_label
    across
    (demography_vars$var_name_orig[which(demography_vars$class_target == "numeric")], as_numeric)
  ) %>%
  mutate ( ## convert to character with keeping var_label
    across
    (demography_vars$var_name_orig[which(demography_vars$class_target == "character")], as.character)
  ) %>%
  mutate ( ## do the same with targeted factor variables (none in this example) 
    across
    (demography_vars$var_name_orig[which(demography_vars$class_target == "factor")], as.factor)
  ) 

It is unclear to me what happens here. Neither the documentation specifies the outcome, nor I do not see anything happening.

library(DDIwR)
#> Also attaching packages: admisc, declared, haven
DDI_demograpy <- convert(demography, to = "DDI", embed=TRUE)
print(DDI_demograpy)
#> NULL
library(knitr)
library(kableExtra)
var_code_table(df = demography, var_name = "d7") %>%
  #mutate (var_name_orig = cell_spec(.data$var_name_orig, align="c")) %>%
  kbl( align = c(rep("c",4), "l")) %>%
  kable_paper(full_width = F, font_size = 10) %>%
  add_header_above(c("id" = 1, "variable properies" = 2, "value properties" = 2)) %>%
  column_spec(1, bold = F, border_right = T, width = "2.5em") %>%
  column_spec(2:4, bold = F, width = "2.5em")  %>%
  column_spec(3, border_right = T)  %>%
  column_spec(5, border_right=T)
id
variable properies
value properties
survey var_name_orig var_label_orig val_code_orig val_label_orig
10.4232/1.13044 d7 MARITAL STATUS 1 (Re-)Married: living without children
10.4232/1.13044 d7 MARITAL STATUS 2 (Re-)Married: w children of this marriage
10.4232/1.13044 d7 MARITAL STATUS 3 (Re-)Married: w children of previous marriage
10.4232/1.13044 d7 MARITAL STATUS 4 (Re-)Married: w children of this and previous marriage
10.4232/1.13044 d7 MARITAL STATUS 5 Single living w partner: without children
10.4232/1.13044 d7 MARITAL STATUS 6 Single living w partner: w children of this union
10.4232/1.13044 d7 MARITAL STATUS 7 Single living w partner: w children of previous union
10.4232/1.13044 d7 MARITAL STATUS 8 Single living w partner: w children of this and previous union
10.4232/1.13044 d7 MARITAL STATUS 9 Single: living without children
10.4232/1.13044 d7 MARITAL STATUS 10 Single: with children
10.4232/1.13044 d7 MARITAL STATUS 11 Divorced/Separated: living without children
10.4232/1.13044 d7 MARITAL STATUS 12 Divorced/Separated: living with children
10.4232/1.13044 d7 MARITAL STATUS 13 Widow/er: living without children
10.4232/1.13044 d7 MARITAL STATUS 14 Widow/er: living with children
10.4232/1.13044 d7 MARITAL STATUS 15 Other (SPONT.)
10.4232/1.13044 d7 MARITAL STATUS 97 Refusal (SPONT.)