https://github.com/skvrnami/hlidacr
Access Data from the Hlídač státu API in R
https://github.com/skvrnami/hlidacr
czech-republic datasets open-data r rstats rstats-package
Last synced: 4 months ago
JSON representation
Access Data from the Hlídač státu API in R
- Host: GitHub
- URL: https://github.com/skvrnami/hlidacr
- Owner: skvrnami
- License: other
- Created: 2020-11-11T14:27:53.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-12-07T18:40:15.000Z (over 3 years ago)
- Last Synced: 2025-12-09T19:17:55.979Z (6 months ago)
- Topics: czech-republic, datasets, open-data, r, rstats, rstats-package
- Language: R
- Homepage:
- Size: 400 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# hlidacr
[](https://CRAN.R-project.org/package=hlidacr)
[](https://github.com/skvrnami/hlidacr/actions)
[](https://codecov.io/gh/skvrnami/hlidacr)
[](https://CRAN.R-project.org/package=hlidacr)
The goal of hlidacr is to provide access to the data published by [Hlídač státu](https://www.hlidacstatu.cz/) provided by their [API](https://www.hlidacstatu.cz/swagger/index.html).
## Installation
You can install the package from CRAN:
``` r
install.packages("hlidacr")
```
You can install the development version from [GitHub](https://github.com/) with:
``` r
# 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](https://www.hlidacstatu.cz/api/v1/Index)
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](https://www.hlidacstatu.cz/swagger/index.html)
of the Hlídač státu API.
The data available via the API are related to:
- funding of political parties
- transcriptions of parliamentary floor debates, municipal council debates and other bodies
- contracts between public institutions and private companies
- subsidies
- availability of websites operated by public institutions
etc.
## 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()`.
```{r example, message=FALSE, warning=FALSE}
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:
- `page`
- `total`: total number of records
- `results`: data
(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:
```{r}
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:
```{r}
golf_subsidies <- search_subsidies("golf")
head(golf_subsidies$results %>% select(idDotace, nazevProjektu, dotaceCelkem))
```
```{r}
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`.
```{r}
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:
```{r}
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.
```{r}
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:
```{r}
twitter_insta <- get_person_social(types = c("Instagram", "Twitter"))
twitter_insta$socialniSite[2]
```