-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
153 lines (113 loc) · 4.56 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# hlidacr
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/hlidacr)](https://CRAN.R-project.org/package=hlidacr)
[![R build status](https://github.com/skvrnami/hlidacr/workflows/R-CMD-check/badge.svg)](https://github.com/skvrnami/hlidacr/actions)
[![codecov](https://codecov.io/gh/skvrnami/hlidacr/branch/main/graph/badge.svg?token=FWP73F1DOL)](https://codecov.io/gh/skvrnami/hlidacr)
[![](https://cranlogs.r-pkg.org/badges/hlidacr)](https://CRAN.R-project.org/package=hlidacr)
<!-- badges: end -->
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]
```