https://github.com/petrbouchal/czso
Use Open Data from the Czech Statistical Office in R
https://github.com/petrbouchal/czso
czech-republic czech-statistical-office czso dataset open-data r rstats rstats-package statistics
Last synced: 9 months ago
JSON representation
Use Open Data from the Czech Statistical Office in R
- Host: GitHub
- URL: https://github.com/petrbouchal/czso
- Owner: petrbouchal
- License: other
- Created: 2020-01-22T14:53:07.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-09-09T21:37:00.000Z (9 months ago)
- Last Synced: 2025-09-10T01:02:42.735Z (9 months ago)
- Topics: czech-republic, czech-statistical-office, czso, dataset, open-data, r, rstats, rstats-package, statistics
- Language: R
- Homepage: https://petrbouchal.xyz/czso
- Size: 2.68 MB
- Stars: 13
- Watchers: 4
- Forks: 1
- Open Issues: 20
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
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%"
)
```
# czso 
[](https://CRAN.R-project.org/package=czso)
[](https://CRAN.R-project.org/package=czso)
[](https://CRAN.R-project.org/package=czso)
[](https://lifecycle.r-lib.org/articles/stages.html)
[](https://github.com/SNStatComp/awesome-official-statistics-software)
[](https://github.com/petrbouchal/czso/actions/workflows/R-CMD-check.yaml)
The goal of czso is to provide direct, programmatic, hassle-free access from R to open data provided by the Czech Statistical Office (CZSO).
This is done by
1. **providing direct access from R to the catalogue of open CZSO datasets**, eliminating the hassle from data discovery. Normally this is done done through [the CZSO's product catalogue](https://www.czso.cz/csu/czso/otevrena-data-v-katalogu-produktu-csu) which is unfortunately a bit clunky, or [data.gov.cz](https://data.gov.cz), which is not a natural starting point for many.
2. **providing a function to load a specific dataset to R** directly from the CZSO's datastore, eliminating the friction of copying a URL, downloading, unzipping etc.
Additionally, the package provides access to metadata on datasets and to codelists (číselníky) as a special case of datasets listed in the catalogue.
## Installation
You can install the package from CRAN:
``` r
install.packages("czso")
```
You can install the latest in-development release from [github](https://github.com/petrbouchal/czso) with:
``` r
remotes::install_github("petrbouchal/czso", ref = github_release())
```
or the latest version with:
``` r
remotes::install_github("petrbouchal/czso")
```
I also keep binaries in a `drat` repo, which you can access by
```
install.packages("czso", repos = "https://petrbouchal.xyz/drat")
```
## Example
Say you are looking for a dataset whose title refers to wages (mzda/mzdy):
First, retrieve the list of available CZSO datasets:
```{r example-catalogue}
library(czso)
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(stringr))
catalogue <- czso_get_catalogue()
```
Now search for your terms of interest in the dataset titles:
```{r example-filter}
catalogue %>%
filter(str_detect(title, "[Mm]zd[ay]")) %>%
select(dataset_id, title, description)
```
You could also search in descriptions or keywords which are also retrieved into the catalogue.
We can see the `dataset_id` for the required dataset - now use it to get the dataset:
```{r example-cont}
czso_get_table("110080")
```
You can retrieve the schema for the dataset:
```{r example-schema}
czso_get_table_schema("110080")
```
and download the documentation in PDF:
```{r example-doc}
czso_get_dataset_doc("110080", action = "download", format = "pdf")
```
If you are interested in linking this data to different data, you might need the NUTS codes for regions. Seeing that the lines with regional breakdown list `uzemi_cis` as `"100"`, you can get that codelist (číselník):
```{r example-codelist}
czso_get_codelist(100)
```
You would then need to do a bit of manual work to join this codelist onto the data.
### A note about "tables" and "datasets"
In the parlance of the official open data catalogue, a `dataset` can have multiple distributions (typically multiple formats of the same data). These are called resources in the internals, and manifest as tables in this package. Some metainformation is the property of a dataset (the documentation), while other - the schema - is the property of a table. Hence the function names in this package. This is to keep things organised even if the CZSO almost always provides only one table per dataset and appends new data to it over time.
## Data sources
The catalogue is drawn from https://data.gov.cz through the [SPARQL endpoint](https://data.gov.cz/sparql).
The data and specific metadata is then accessed via the `package_show` endpoint of the CZSO API at (example) https://vdb.czso.cz/pll/eweb/package_show?id=290038r19.
## Credit and notes
- not created or endorsed by the Czech Statistical Office, though they, as well as [the open data team at the Ministry of Interior](https://data.gov.cz/) deserve credit for getting the data out there.
- the package relies on the data.gov.cz catalogue of open data and on the CZSO's local catalogue
- NB: The robots.txt at the domain hosting the CZSO's catalogue prohibits robots from accessing it; while this may be an inappropriate/erroneous setting for what is in essence a data API, this package tries to honor the spirit of that setting by only accessing the API once per `czso_get_table()` call, relying on a different system for `czso_get_catalogue()`. Hence, *do not use this package for harvesting large numbers of datasets from the CZSO.*
### Acknowledgments
Thanks to @jakubklimek and @martinnecasky for [helping me figure out](https://github.com/datagov-cz/nkod/issues/19) the [SPARQL endpoint](https://data.gov.cz/sparql) on the Czech National Open Data Catalogue.
### The logo
An homage to the CZSO's work in releasing its data in an open format, something that is not necessarily in its DNA.
It alludes to the shades of the country reflected in the tabular data provided, By interspersing the comma symbol into the name of the package, it refers to both integration between statistics and open data and the slight disruption that the world of statistics undergoes when that integration happens.
## See also
This package takes inspiration from the packages
- [eurostat](https://github.com/rOpenGov/eurostat/)
- [OECD](https://github.com/expersso/OECD)
which are very useful in their own right - much recommended.
For Czech geospatial data, see [CzechData](https://github.com/JanCaha/CzechData/) by [JanCaha](https://github.com/JanCaha/).
For Czech fiscal data, see [statnipokladna](https://github.com/petrbouchal/statnipokladna).
For various transparency disclosures, see [Hlídač státu](https://www.hlidacstatu.cz/) and the [{hlidacr}](https://cran.r-project.org/package=hlidacr) package.
For access to some of Prague's open geospatial data in R, see [pragr](https://github.com/petrbouchal/pragr).
## Contributing / code of conduct
Please note that the 'czso' project is released with a
[Contributor Code of Conduct](https://petrbouchal.xyz/czso/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.