Title: Interface to the Comparative Legislators Database
Description: Facilitates access to the Comparative Legislators Database (CLD). The CLD includes political, sociodemographic, career, online presence, public attention, and visual information for over 67,000 contemporary and historical politicians from 16 countries.
Version: 1.1.0
URL: https://github.com/saschagobel/legislatoR
BugReports: https://github.com/saschagobel/legislatoR/issues
License: GPL-3
Depends: R (≥ 3.5.0)
Imports: curl (≥ 3.0), dplyr (≥ 0.7.4)
Suggests: testthat, rmarkdown, knitr, magrittr, purrr, stringr, tibble
VignetteBuilder: knitr
Encoding: UTF-8
RoxygenNote: 7.1.2
NeedsCompilation: no
Packaged: 2023-03-31 20:38:18 UTC; Sascha
Author: Sascha Goebel ORCID iD [aut, cre], Simon Munzert [aut]
Maintainer: Sascha Goebel <sascha.goebel@soz.uni-frankfurt.de>
Repository: CRAN
Date/Publication: 2023-03-31 21:00:02 UTC

List content of the CLD

Description

Returns a named list of legislatures and sessions available in the CLD. This provides a quick overview of the CLD's scope and valid three-letter country codes, and helps to conventiently loop/map over legislatures and sessions.

Usage

cld_content(legislature = NULL)

Arguments

legislature

An optional character string specifying one or more legislatures. Currently one of ‘aut’, ‘can’, ‘cze’, ‘esp’, ‘fra’, ‘deu’, ‘irl’, ‘sco’, ‘gbr’, ‘usa_house’, or ‘usa_senate’. If NULL (the default), a list with all legislatures and sessions available in the CLD is returned.

Value

A list with names being three-letter country codes and with each element containing a vector that shows the sessions available for a legislature.

Examples

# Get a list of three-letter country codes and available sessions for all countries
overview <- cld_content()
tibble::glimpse(overview)

# Get a list of available sessions for the French Assemblée and the Irish Dail
sessions <- cld_content(legislature = c("fra", "irl"))
tibble::glimpse(sessions)

Fetch 'Core' table

Description

Fetches sociodemographic data of legislators for the specified legislature. Requires a working Internet connection.

Usage

get_core(legislature)

Arguments

legislature

A character string specifying the three-letter country code of the legislature for which data shall be fetched. Currently one of ‘aut’, ‘can’, ‘cze’, ‘esp’, ‘fra’, ‘deu’, ‘irl’, ‘sco’, ‘gbr’, ‘usa_house’, or ‘usa_senate’.

Format

Data frame with columns (varies by legislature):

Value

A data frame with columns as specified above.

Source

Wikipedia, https://www.wikipedia.org/
Wikipedia API, https://en.wikipedia.org/w/api.php
Wikidata API, https://www.wikidata.org/wiki/Wikidata:Main_Page
Wikimedia Commons, https://commons.wikimedia.org/wiki/Main_Page
Face++ Cognitive Services API, https://www.faceplusplus.com/
Germany Bundestag Open Data, https://www.bundestag.de/services/opendata

Examples

# Get entire 'Core' table for the German Bundestag
deu_core <- get_core(legislature = "deu")
tibble::glimpse(deu_core)

# Get 'Core' table for 16th session of the German Bundestag
deu_core_subset <- dplyr::semi_join(x = deu_core,
                                    y = dplyr::filter(get_political(legislature = "deu"),
                                                      session == 16),
                                    by = "pageid")
tibble::glimpse(deu_core_subset)


Fetch Wikipedia 'History' table

Description

Fetches full revision histories of legislators' Wikipedia biographies for the specified legislature. Requires a working Internet connection.

Usage

get_history(legislature)

Arguments

legislature

A character string specifying the three-letter country code of the legislature for which data shall be fetched. Currently one of ‘aut’, ‘can’, ‘cze’, ‘esp’, ‘fra’, ‘deu’, ‘irl’, ‘sco’, ‘gbr’, ‘usa_house’, or ‘usa_senate’.

Format

Data frame with columns:

Value

A data frame with columns as specified above.

Source

Wikipedia API, https://en.wikipedia.org/w/api.php

Examples

# Get entire 'History' table for the Austrian Nationalrat
aut_history <- get_history(legislature = "aut")
tibble::glimpse(aut_history)

# Get 'History' table for NEOS party members of the Austrian Nationalrat
aut_history_subset <- dplyr::semi_join(x = aut_history,
                                       y = dplyr::filter(get_political(legislature = "aut"),
                                                         party == "NEOS"),
                                       by = "pageid")
tibble::glimpse(aut_history_subset)


Fetch 'IDs' table

Description

Fetches a range of IDs of legislators for the specified legislature. Requires a working Internet connection.

Usage

get_ids(legislature)

Arguments

legislature

A character string specifying the three-letter country code of the legislature for which data shall be fetched. Currently one of ‘aut’, ‘can’, ‘cze’, ‘esp’, ‘fra’, ‘deu’, ‘irl’, ‘sco’, ‘gbr’, ‘usa_house’, or ‘usa_senate’.

Format

Data frame with columns (varies by legislature):

Value

A data frame with columns as specified above.

Source

Wikidata API, https://www.wikidata.org/wiki/Wikidata:Main_Page

Examples

# Get entire 'IDs' table for the for the United States Senate
usa_ids <- get_ids(legislature = "usa_senate")
tibble::glimpse(usa_ids)

# Get ICPSR IDs and add 'Offices' table for the United States House
usa_ids_subset <- dplyr::inner_join(x = dplyr::filter(usa_ids,
                                                      !is.na(icpsr)),
                                    y = get_office(legislature = "usa_senate"),
                                    by = "wikidataid")
tibble::glimpse(usa_ids_subset)


Fetch 'Offices' table

Description

Fetches political and other offices of legislators for the specified legislature. Requires a working Internet connection.

Usage

get_office(legislature)

Arguments

legislature

A character string specifying the three-letter country code of the legislature for which data shall be fetched. Currently one of ‘aut’, ‘can’, ‘cze’, ‘esp’, ‘fra’, ‘deu’, ‘irl’, ‘sco’, ‘gbr’, ‘usa_house’, or ‘usa_senate’.

Format

Data frame in wide format with columns (varies by legislature):

Value

A data frame with columns as specified above.

Source

Wikidata API, https://www.wikidata.org/wiki/Wikidata:Main_Page

Examples

# Get entire 'Offices' table for the United States Senate
usa_offices <- get_office(legislature = "usa_senate")
tibble::glimpse(usa_offices)

# Get 'Offices' table for male members of the United States Senate
usa_offices_subset <- dplyr::semi_join(x = usa_offices,
                                       y = dplyr::filter(get_core(legislature = "usa_senate"),
                                                           sex == "female"),
                                         by = "wikidataid")
tibble::glimpse(usa_offices_subset)


Fetch 'Political' table

Description

Fetches political data of legislators for the specified legislature. Requires a working Internet connection.

Usage

get_political(legislature)

Arguments

legislature

A character string specifying the three-letter country code of the legislature for which data shall be fetched. Currently one of ‘aut’, ‘can’, ‘cze’, ‘esp’, ‘fra’, ‘deu’, ‘irl’, ‘sco’, ‘gbr’, ‘usa_house’, or ‘usa_senate’.

Format

Data frame in long format with columns (varies by legislature):

Value

A data frame with columns as specified above.

Source

Wikipedia, https://www.wikipedia.org/
Czech Republic Parliamentary Members Archive https://public.psp.cz/sqw/fsnem.sqw?zvo=1
Spain Parliamentary Members Archive https://www.congreso.es/es/busqueda-de-diputados

Examples

# Get entire 'Political' table for the Czech Poslanecka Snemovna
cze_political <- get_political(legislature = "cze")
tibble::glimpse(cze_political)

# Get 'Political' table for female DSP party members of the Czech Poslanecka Snemovna
cze_political_subset <- dplyr::semi_join(x = dplyr::filter(cze_political,
                                                           party == "ODS"),
                                         y = dplyr::filter(get_core(legislature = "cze"),
                                                           sex == "female"),
                                         by = "pageid")
tibble::glimpse(cze_political_subset)


Fetch 'Portrait' table

Description

Fetches portrait urls of legislators for the specified legislature. Requires a working Internet connection.

Usage

get_portrait(legislature)

Arguments

legislature

A character string specifying the three-letter country code of the legislature for which data shall be fetched. Currently one of ‘aut’, ‘can’, ‘cze’, ‘esp’, ‘fra’, ‘deu’, ‘irl’, ‘sco’, ‘gbr’, ‘usa_house’, or ‘usa_senate’.

Format

Data frame with columns (varies by legislature):

Value

A data frame with columns as specified above.

Source

Wikipedia API, https://en.wikipedia.org/w/api.php
Wikimedia Commons, https://commons.wikimedia.org/wiki/Main_Page

Examples

# Get entire 'Portraits' table for the United States Senate
usa_portraits <- get_portrait(legislature = "usa_senate")
tibble::glimpse(usa_portraits)

# Get 'Portraits' table for Democratic members of the United States Senate
usa_port_subset <- dplyr::semi_join(x = usa_portraits,
                                    y = dplyr::filter(get_political(legislature = "usa_senate"),
                                                                    party == "D"),
                                    by = "pageid")
tibble::glimpse(usa_port_subset)


Fetch 'Professions' table

Description

Fetches occupational data of legislators for the specified legislature. Requires a working Internet connection.

Usage

get_profession(legislature)

Arguments

legislature

A character string specifying the three-letter country code of the legislature for which data shall be fetched. Currently one of ‘aut’, ‘can’, ‘cze’, ‘esp’, ‘fra’, ‘deu’, ‘irl’, ‘sco’, ‘gbr’, ‘usa_house’, or ‘usa_senate’.

Format

Data frame in wide format with columns (varies by legislature):

Value

A data frame with columns as specified above.

Source

Wikidata API, https://www.wikidata.org/wiki/Wikidata:Main_Page

Examples

# Get entire 'Professions' table for the United States House
usa_offices <- get_office(legislature = "usa_house")
tibble::glimpse(usa_offices)

# Get 'Professions' table for female members of the United States House
usa_offices_subset <- dplyr::semi_join(x = usa_offices,
                                       y = dplyr::filter(get_core(legislature = "usa_house"),
                                                         sex == "female"),
                                       by = "wikidataid")
tibble::glimpse(usa_offices_subset)


Fetch 'Social' table

Description

Fetches social media handles and website URLs of legislators for the specified legislature. Requires a working Internet connection.

Usage

get_social(legislature)

Arguments

legislature

A character string specifying the three-letter country code of the legislature for which data shall be fetched. Currently one of ‘aut’, ‘can’, ‘cze’, ‘esp’, ‘fra’, ‘deu’, ‘irl’, ‘sco’, ‘gbr’, ‘usa_house’, or ‘usa_senate’.

Format

Data frame with columns (varies by legislature):

Value

A data frame with columns as specified above.

Source

Wikidata API, https://www.wikidata.org/wiki/Wikidata:Main_Page

Examples

# Get entire 'Social' table forthe UK House of Commons
gbr_social <- get_social(legislature = "gbr")
tibble::glimpse(gbr_social)

# Get 'Social' table for members of the UK House of Commons with available TheyWorkForYou ID
gbr_social_subset <- dplyr::semi_join(x = gbr_social,
                                      y = dplyr::filter(get_ids(legislature = "gbr"),
                                                        !is.na(theyworkforyou)),
                                      by = "wikidataid")
tibble::glimpse(gbr_social_subset)


Fetch Wikipedia 'Traffic' table

Description

Fetches daily user traffic on legislators' Wikipedia biographies for the specified legislature. Requires a working Internet connection.

Usage

get_traffic(legislature)

Arguments

legislature

A character string specifying the three-letter country code of the legislature for which data shall be fetched. Currently one of ‘aut’, ‘can’, ‘cze’, ‘esp’, ‘fra’, ‘deu’, ‘irl’, ‘sco’, ‘gbr’, ‘usa_house’, or ‘usa_senate’.

Format

Data frame with columns:

Value

A data frame with columns as specified above.

Source

Wikimedia API, https://wikimedia.org/api/rest_v1/
http://petermeissner.de:8880/

Examples

# Get entire 'Traffic' table for the Scottish Parliament
sco_traffic <- get_traffic(legislature = "sco")
tibble::glimpse(sco_traffic)

# Add Wikidataid to 'Traffic' table for the Scottish Parliament
sco_traffic_subset <- dplyr::inner_join(x = dplyr::select(get_core(legislature = "sco"),
                                                          pageid, wikidataid),
                                        y = sco_traffic,
                                        by = "pageid")
tibble::glimpse(sco_traffic_subset)


legislatoR

Description

Facilitates access to the Comparative Legislators Database (CLD). The CLD includes political, sociodemographic, career, online presence, public attention, and visual information for over 45,000 contemporary and historical politicians from ten countries.

legislatoR functions

cld_content: returns a named list of legislatures and sessions available in the CLD.

get_core: fetches sociodemographic data of legislators.

get_political: fetches political data of legislators.

get_history: fetches full revision histories of legislators' Wikipedia biographies.

get_traffic: fetches daily user traffic on legislators' Wikipedia biographies.

get_social: fetches social media handles and website URLs of legislators.

get_portrait: fetches portrait urls of legislators.

get_office: fetches political and other offices of legislators.

get_profession fetches occupational data of legislators.

get_ids: fetches a range of IDs of legislators.