load_gerda_web: Load GERDA Data

View source: R/load_gerda_web.R

load_gerda_webR Documentation

Load GERDA Data

Description

This function loads GERDA data from a web source.

Usage

load_gerda_web(
  file_name,
  verbose = FALSE,
  file_format = "rds",
  on_error = getOption("gerda.on_error", "warn"),
  timeout = getOption("gerda.timeout", 300),
  max_retries = getOption("gerda.max_retries", 2),
  cache = getOption("gerda.cache", FALSE),
  refresh = FALSE
)

Arguments

file_name

A character string specifying the name of the file to load. For a list of available data, see gerda_data_list.

verbose

A logical value indicating whether to print additional messages to the console. Default is FALSE.

file_format

A character string specifying the format of the file. Must be either "csv" or "rds". Default is "rds".

on_error

How to handle errors (unknown dataset name, failed download, corrupt file, invalid file_format). Either "warn" (default) to emit a warning and return NULL, or "stop" to raise an error. Use "stop" inside scripts or pipelines where silent NULL returns would produce confusing downstream failures. The global default can also be overridden with options(gerda.on_error = "stop").

timeout

Download timeout in seconds. Defaults to getOption("gerda.timeout", 300). The value is applied only for the duration of the download (raising R's default of 60s, which is too short for the larger GERDA files) and restored afterwards.

max_retries

Number of additional download attempts after the first, with exponential backoff, if a download fails or returns a Git LFS pointer instead of data. Defaults to getOption("gerda.max_retries", 2) (so up to three attempts in total).

cache

Logical; if TRUE, downloaded datasets are cached on disk (in gerda_cache_dir()) and reused on subsequent calls instead of being re-downloaded. Defaults to getOption("gerda.cache", FALSE). Caching is opt-in so the package never writes to user filespace without consent. See clear_gerda_cache() to purge the cache.

refresh

Logical; if TRUE, ignore any cached copy and force a fresh download (updating the cache when cache = TRUE). Default is FALSE.

Value

A tibble containing the loaded data, or NULL if the data could not be loaded.

Vote-share columns

Election datasets expose one column per party (e.g. cdu, spd, gruene, afd). These columns hold the party's share of valid votes and are expressed as fractions of 1. They do not sum to 1 across the named major parties: the remainder is held by smaller parties with their own columns and, at the tail, an other category. For example, in federal_cty_harm for 2021, cdu + csu + spd + gruene + fdp + linke_pds + afd is typically around 0.91 and ranges roughly 0.78 to 0.97 across counties. To reconstruct a full 1.0 share, include every party column or use other together with turnout and invalid-vote columns.

See Also

gerda_data_list() for the dataset catalog, clear_gerda_cache() and gerda_cache_dir() for cache management.

Examples

# These examples download datasets from GitHub (up to ~125 MB each) and are
# therefore not run automatically.
## Not run: 
# Load harmonized municipal elections data
data_municipal_harm <- load_gerda_web("municipal_harm", verbose = TRUE, file_format = "rds")

# Load federal election data harmonized to 2025 boundaries (includes 2025 election)
data_federal_2025 <- load_gerda_web("federal_muni_harm_25", verbose = TRUE, file_format = "rds")

# Cache the download so repeated calls in the same project reuse it. Caching
# is opt-in because it writes to gerda_cache_dir() outside the session's
# temporary directory.
data_federal_2025 <- load_gerda_web("federal_muni_harm_25", cache = TRUE)

## End(Not run)


gerda documentation built on July 27, 2026, 5:09 p.m.