cbsodata4

February 9, 2021 · View on GitHub

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")]
IdentifierTitle
481075nedWerkloze beroepsbevolking; werkloosheidsduur en persoonskenmerken 2003-2018
581575NEDVestigingen van bedrijven; bedrijfstak, gemeente
682245NEDBevolking en huishoudens; viercijferige postcode, 1 januari 2013
783433NEDConsumentenprijzen; werknemers laag, alle basisjaren 1969-1995
883435NEDAmsterdam 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")]
IdentifierTitle
M003026Theoretisch beschikbare uren
M002994_2Totaal niet-productieve uren
M003031Vorst- en neerslagverlet
M003013Overig
M003019Productieve uren
# dimensions
meta$Dimensions[, c("Identifier", "Title")]
IdentifierTitle
PeriodenPerioden

Retrieve data with cbs4_get_data:

# wide format, each measure its own column
data <- cbs4_get_data("60006")
head(data[, 1:4])
PeriodenTotaal niet-productieve urenOverigProductieve uren
1990JJ006956451390
1990KW01155135365
1990KW02130125390
1990KW03250240270
1990KW04160145370
1991JJ007806651305

or cbs4_get_observations

# long format, one Value column
obs <- cbs4_get_observations("60006")
head(obs)
IdMeasureValueAttributeValuePerioden
0M003026None5201990KW01
1M002994_2None1551990KW01
2M003031None201990KW01
3M003013None1351990KW01
4M003019None3651990KW01
5M003026None5201990KW02

Add labels to a dataset with cbs4_add_label_columns:

data <- cbs4_add_label_columns(data)
head(data[,1:5])
PeriodenPeriodenLabelTotaal niet-productieve urenOverigProductieve uren
1990JJ0019906956451390
1990KW011990 1e kwartaal155135365
1990KW021990 2e kwartaal130125390
1990KW031990 3e kwartaal250240270
1990KW041990 4e kwartaal160145370
1991JJ0019917806651305
obs <- cbs4_add_label_columns(obs)
head(obs)
IdMeasureMeasureLabelValueAttributeValuePeriodenPeriodenLabel
0M003026Theoretisch beschikbare urenNone5201990KW011990 1e kwartaal
1M002994_2Totaal niet-productieve urenNone1551990KW011990 1e kwartaal
2M003031Vorst- en neerslagverletNone201990KW011990 1e kwartaal
3M003013OverigNone1351990KW011990 1e kwartaal
4M003019Productieve urenNone3651990KW011990 1e kwartaal
5M003026Theoretisch beschikbare urenNone5201990KW021990 2e kwartaal

Find non-standard CBS catalogs with cbs4_get_catalogs:

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

For more information see vignette("cbsodata4")