library(eurobarometer)
library(dplyr)
library(stringr)

The eb_sample is a small fraction of the GESIS datafile ZA5479_v6-0-0.sav. It cannot be used to retrieve any statistical data from the original dataset. In scope it is limited to some important metadata columns, a few demographic variables and one question block. In geographic coverage, it takes a sample from the responses from the United Kingdom and Germany. These two countries are targeting parts of the countries separately, i.e. for Great Britain and Northern Ireland, and the former West Germany and East Germany.

sample <- eurobarometer:::eb_sample
sample_metadata <- gesis_metadata_create(dat = sample)

The function gesis_metadta_create normalizes those variable names that are not machine readable. These names are still often problematic and require adjustment.

adjusted_metadata <- sample_metadata %>%
  mutate ( canonical_names = case_when (
    str_sub(normalized_name, 1,3) == "p6_|p7_" ~ str_sub(normalized_name, 4,-1),
    normalized_name == "w1_weight_result_from_target" ~ 'w1',
    TRUE ~ normalized_name
  ))

You can, if you know what you are doing, change the suggested base R representation of your survey data in the column

renamed_sample <- sample %>%
  purrr::set_names ( adjusted_metadata$canonical_names)

converted <- convert_class (dat = renamed_sample,
               metadata = adjusted_metadata,
               var_name = "canonical_names",
               conversion = "conversion_suggestion")

converted %>%
  dplyr::select( all_of(c("w1",
                          "age_exact",
                          "is_energy_saving_action_used_car_less"))) %>%
  dplyr::sample_n(., 10) %>%
  kable()
w1 age_exact is_energy_saving_action_used_car_less
1.2327 54 0
0.9164 63 0
1.2850 26 1
0.8847 51 0
0.9163 49 0
1.6707 20 0
0.6078 69 0
1.5220 31 0
0.9163 42 0
0.8726 63 0