knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" ) api_token <- Sys.getenv("BUNDESTAG_API") library(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
You can install the latest version of tidybundestag from Github with
remotes::install_github("benjaminguinaudeau/tidybundestag")
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.
library(tidybundestag)
Once you have an api-key, you can start accessing data:
bt_vorgang(n_max = 100) %>% dplyr::glimpse()
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
.
bt_aktivitaet(n_max = 100) %>% dplyr::glimpse()
bt_drucksache(n_max = 100) %>% dplyr::glimpse()
bt_drucksache_text(n_max = 20) %>% dplyr::glimpse()
bt_person(n_max = 20) %>% dplyr::glimpse()
bt_plenarprotokoll(n_max = 100) %>% dplyr::glimpse()
bt_plenarprotokoll_text(n_max = 20) %>% dplyr::glimpse()
bt_vorgang(n_max = 100) %>% dplyr::glimpse()
bt_vorgangsposition(n_max = 100) %>% dplyr::glimpse()
c('BT', 'BR', 'BV', 'EK')
)bt_vorgang(id = "279665")
bt_drucksache_text(id = c("239894", "234517"))
bt_vorgang(n_max = 100, start_date = "2021-01-01") %>% dplyr::glimpse()
bt_drucksache(n_max = 100, end_date = "2020-01-01") %>% dplyr::glimpse()
bt_vorgang(drucksache = 68852) %>% dplyr::glimpse()
bt_vorgang(plenarprotokoll = 908) %>% dplyr::glimpse()
bt_plenarprotokoll(n_max = 100, zuordnung = "BT") %>% dplyr::glimpse()
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.