knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

api_token <- Sys.getenv("BUNDESTAG_API")
library(tidybundestag)

tidybundestag

tidybundestag wraps up the official API of the German Bundestag in R.

It can be used to retrieve data on:

For more information on the API, please visit: https://dip.bundestag.de/documents/informationsblatt_zur_dip_api.pdf

Installation

You can install the latest version of tidybundestag from Github with

remotes::install_github("benjaminguinaudeau/tidybundestag")

Api Key

Access to the API is controlled with an API key. To obtain this api-key please visit the Bundestag website.

tidybundestag functions will read the API key from the environment variable BUNDESTAG_API. In order to add your key to your environment file, you can use the function edit_r_environ() from the {{usethis}}.

This will open your .Renviron file in your text editor. Now, you can add the following line to it:

BUNDESTAG_API="YOUR_API_KEY"

Save the file and restart R for the changes to take effect.

Alternatively, you can provide an explicit definition of your API key with each function call using the api_token argument.

Example

library(tidybundestag)

Once you have an api-key, you can start accessing data:

bt_vorgang(n_max = 100) %>%
  dplyr::glimpse()

Endpoints

The API of the Bundestag proposes 8 different endpoints.

tidybundestag always returns a tibble where each row represents one unit (i.e. one process, one plenary, one questions, one person, etc...). The original json-structure is embedded in the tibble as a list-column, that can be easily handled with tidyr.

Activities

bt_aktivitaet(n_max = 100) %>%
  dplyr::glimpse()

Drucksache

bt_drucksache(n_max = 100) %>%
  dplyr::glimpse()

Drucksache-Text

bt_drucksache_text(n_max = 20) %>%
  dplyr::glimpse()

Person

bt_person(n_max = 20) %>%
  dplyr::glimpse()

Plenarprotokoll

bt_plenarprotokoll(n_max = 100) %>%
  dplyr::glimpse()

Text of plenarprotokoll

bt_plenarprotokoll_text(n_max = 20) %>%
  dplyr::glimpse()

Vorgang

bt_vorgang(n_max = 100) %>%
  dplyr::glimpse()

Vorgangsposition

bt_vorgangsposition(n_max = 100) %>%
  dplyr::glimpse()

Query Parameter

id (one or several)

bt_vorgang(id = "279665")
bt_drucksache_text(id = c("239894", "234517"))

start_date

bt_vorgang(n_max = 100, start_date = "2021-01-01") %>%
  dplyr::glimpse()

end_date

bt_drucksache(n_max = 100, end_date = "2020-01-01") %>%
  dplyr::glimpse()

drucksache

bt_vorgang(drucksache = 68852) %>%
  dplyr::glimpse()

plenarprotokoll

bt_vorgang(plenarprotokoll = 908) %>%
  dplyr::glimpse()

zuordnung

bt_plenarprotokoll(n_max = 100, zuordnung = "BT") %>%
  dplyr::glimpse()

Unnest list-columns

members <- bt_person(n_max = 200) %>%
  dplyr::glimpse()

roles <- members %>%
  tidyr::unnest(person_roles, names_sep = "_", keep_empty = T) %>%
  dplyr::glimpse()
roles %>%
  dplyr::filter(!is.na(person_roles_funktion)) %>%
  dplyr::count(person_roles_funktion) %>%
  ggplot2::ggplot(ggplot2::aes(person_roles_funktion, n)) +
  ggplot2::geom_col() +
  ggplot2::coord_flip()


benjaminguinaudeau/tidybundestag documentation built on March 6, 2024, 4:29 p.m.