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

hlidacr

CRAN status R build status codecov

The goal of hlidacr is to provide access to the data published by Hlídač státu provided by their API.

Installation

You can install the package from CRAN:

install.packages("hlidacr")

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("skvrnami/hlidacr")

Besides the installation, you need access token for making API requests. The access token is available here after the registration at the Hlídač státu's website.

Usage

The package implements functions for accessing all publicly available API endpoints as defined in the documentation of the Hlídač státu API.

The data available via the API are related to:

Example

There are two types of datasets available at the Hlídač státu API. First, there are various collection of datasets whose list is available using get_datasets().

library(dplyr)
library(hlidacr)

# Authorization token
TOKEN <- Sys.getenv("HLIDAC_TOKEN")

datasets <- get_datasets(token = TOKEN)
str(datasets, max.level = 1)

head(datasets$results[,1:2], 10)

In general, the data are usually returned in a list with 3 elements:

(Therefore, to get the data you need to iterate over the pages by specifying particular page of the results you want. However, be aware of the fact that the API returns error if the parameter page exceeds 200.)

The data from these datasets can be obtained by get_dataset_data function using dataset's ID. For example:

ministers <- get_dataset_data("ministri", page = 1)
head(ministers$results %>% select(resort, jmeno, strana, zacatek))

Second, there are specific datasets that are available via specific routes and therefore specific functions. These include datasets related to contracts between public institutions and private companies, subsidies, companies, persons and websites.

For example:

golf_subsidies <- search_subsidies("golf")
head(golf_subsidies$results %>% select(idDotace, nazevProjektu, dotaceCelkem))
golf_contracts <- search_contracts("golf")
head(golf_contracts$results %>% select(predmet, hodnotaBezDph))

In addition, you can get the text of particular contract using get_contract_text using the ID of the contract that is stored in the column id in the data.frame returned by search_contracts.

con_text <- get_contract_text(id = "9934567")
cat(substr(con_text[1], 1500, 2000))

Searching for a person is done using search_person. For instance:

babis <- search_person("Babiš")
head(babis)

get_person function provides data related to a person such as their donations to political parties, service in public and private institutions and their social media accounts. The example below shows Andrej Babiš's donations to political parties.

ab <- get_person("andrej-babis")
head(ab$sponzoring %>% arrange(desc(castka)))

Besides getting social media accounts for a particular person using the get_person function, you can obtain social media accounts of Czech politicians, using get_person_social. It returns a data.frame with a data.frame nested in the socialniSite variable. For instance:

twitter_insta <- get_person_social(types = c("Instagram", "Twitter"))
twitter_insta$socialniSite[2]


skvrnami/hlidacr documentation built on Sept. 16, 2021, 5:20 p.m.