Skip to content

R package to access the OData4 interface of data and metadata of Statistics Netherlands (CBS)

License

Notifications You must be signed in to change notification settings

statistiekcbs/cbsodata4

Repository files navigation

URL address changed of odata4 service, if you have a lower version than 0.9.1, please reinstall…

cbsodata4

CRAN status R build status AppVeyor build status Codecov test coverage

The goal of cbsodata4 is allowing access to the Open Data API v4 of Statistics Netherlands.

It is the successor of R package cbsodataR.

  • It uses the new / more efficient OData4 API

  • The download storage is faster (using data.table)

  • It offers a familiar wide data format for users (cbs4_get_data) as well as the default long format (cbs4_get_observations).

Installation

At the moment only a development version can be installed from GitHub with:

# install.packages("devtools")
devtools::install_github("statistiekcbs/cbsodata4")

Usage

library(cbsodata4)

Retrieve a list of all CBS / Statistics Netherlands tables with cbs4_get_datasets:

# download the set of datasets
datasets <- cbs4_get_datasets()
datasets[1:5, c("Identifier", "Title")]
Identifier Title
4 81075ned Werkloze beroepsbevolking; werkloosheidsduur en persoonskenmerken 2003-2018
5 81575NED Vestigingen van bedrijven; bedrijfstak, gemeente
6 82245NED Bevolking en huishoudens; viercijferige postcode, 1 januari 2013
7 83433NED Consumentenprijzen; werknemers laag, alle basisjaren 1969-1995
8 83435NED Amsterdam Airport Schiphol; passagiersvervoer, partnerluchthaven

Get metadata of table <Identifier> (e.g. 60006) with cbs4_get_metadata:

meta <- cbs4_get_metadata(id="60006")
print(meta)
#> cbs odatav4: '60006':
#> "Bouwnijverheid; productieve uren in de burgerlijke en utiliteitsbouw"
#> dimensions: Perioden
#> For more info use 'str(meta)' or 'names(meta)' to find out its properties.
meta$Properties$Title
#> [1] "Bouwnijverheid; productieve uren in de burgerlijke en utiliteitsbouw"
# topics / measures
meta$MeasureCodes[,c("Identifier", "Title")]
Identifier Title
M003026 Theoretisch beschikbare uren
M002994_2 Totaal niet-productieve uren
M003031 Vorst- en neerslagverlet
M003013 Overig
M003019 Productieve uren
# dimensions
meta$Dimensions[, c("Identifier", "Title")]
Identifier Title
Perioden Perioden

Retrieve data with cbs4_get_data:

# wide format, each measure its own column
data <- cbs4_get_data("60006")
head(data[, 1:4])
Perioden Totaal niet-productieve uren Overig Productieve uren
1990JJ00 695 645 1390
1990KW01 155 135 365
1990KW02 130 125 390
1990KW03 250 240 270
1990KW04 160 145 370
1991JJ00 780 665 1305

or cbs4_get_observations

# long format, one Value column
obs <- cbs4_get_observations("60006")
head(obs)
Id Measure ValueAttribute Value Perioden
0 M003026 None 520 1990KW01
1 M002994_2 None 155 1990KW01
2 M003031 None 20 1990KW01
3 M003013 None 135 1990KW01
4 M003019 None 365 1990KW01
5 M003026 None 520 1990KW02

Add labels to a dataset with cbs4_add_label_columns:

data <- cbs4_add_label_columns(data)
head(data[,1:5])
Perioden PeriodenLabel Totaal niet-productieve uren Overig Productieve uren
1990JJ00 1990 695 645 1390
1990KW01 1990 1e kwartaal 155 135 365
1990KW02 1990 2e kwartaal 130 125 390
1990KW03 1990 3e kwartaal 250 240 270
1990KW04 1990 4e kwartaal 160 145 370
1991JJ00 1991 780 665 1305
obs <- cbs4_add_label_columns(obs)
head(obs)
Id Measure MeasureLabel ValueAttribute Value Perioden PeriodenLabel
0 M003026 Theoretisch beschikbare uren None 520 1990KW01 1990 1e kwartaal
1 M002994_2 Totaal niet-productieve uren None 155 1990KW01 1990 1e kwartaal
2 M003031 Vorst- en neerslagverlet None 20 1990KW01 1990 1e kwartaal
3 M003013 Overig None 135 1990KW01 1990 1e kwartaal
4 M003019 Productieve uren None 365 1990KW01 1990 1e kwartaal
5 M003026 Theoretisch beschikbare uren None 520 1990KW02 1990 2e kwartaal

Find non-standard CBS catalogs with cbs4_get_catalogs:

catalogs <- cbs4_get_catalogs()
catalogs[,c("Identifier", "Title")]
Identifier Title
CBS CBS databank StatLine
CBS-asd CBS aanvullend

For more information see vignette("cbsodata4")

About

R package to access the OData4 interface of data and metadata of Statistics Netherlands (CBS)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages