Skip to contents

Reads in the FOKUS survey dataset generated by export_survey_data() for the specified ballot date in the specified canton and language, optionally merged with all prior survey datasets for that canton and language.

Usage

read_survey_data(
  ballot_date = pal::pkg_config_val("ballot_date"),
  canton = cantons(ballot_date),
  lang = pal::pkg_config_val("lang"),
  merged = FALSE,
  use_cache = TRUE,
  auth_token = pal::pkg_config_val("token_repo_private")
)

Arguments

ballot_date

FOKUS-covered ballot date. One of

  • "2018-09-23"

  • "2018-11-25"

  • "2019-10-20"

  • "2020-09-27"

  • "2020-10-18"

  • "2021-11-28"

  • "2023-06-18"

  • "2024-10-20"

canton

FOKUS-covered canton name. One of

  • "aargau"

lang

Language. One of "de".

merged

Whether or not to read in the merged dataset that includes the data from all ballot dates up until ballot_date that were covered by FOKUS surveys in the specified canton. See section Merged data below for details. If FALSE, only the data for ballot_date itself is returned.

use_cache

Whether or not to return cached results if possible. Caching is done based on file content hashing, so the file is only newly fetched if it actually changed since the last download. If FALSE, the file is always newly fetched.

auth_token

Personal access token of a gitlab.com account with access to the private FOKUS repository.

Value

A tibble.

Merged data

Merged datasets differ from single-ballot-date datasets in two ways:

  1. Column labels (the label attribute) are ballot-date-independent, i.e. do not include proposal or election names, and in case of question rewordings over time, the very latest question wording of all FOKUS surveys in that canton is used (which might have been introduced only after ballot_date). So be aware that the questions in the labels do not necessarily correspond to the actual questions asked in the FOKUS survey for ballot_date.

  2. Variables whose factor levels vary across ballot dates, such as those capturing skill questions, are converted to type character. Be aware that these variables usually aren't really comparable over time.

Examples

# GitLab PAT with access to the private FOKUS repository is required for this function to work
try(
  fokus::read_survey_data(ballot_date = "2023-06-18",
                          canton = "aargau",
                          lang = "en") |>
    nrow()
)
#> [1] 2309

try(
  fokus::read_survey_data(ballot_date = "2023-06-18",
                          canton = "aargau",
                          lang = "en",
                          merged = TRUE) |>
    nrow()
)
#> [1] 12506