This package gives access to information made available with the OData (V3) interface.
It is tested on the information from Statistics Netherlands and therefore the root has as default the value https://opendata.cbs.nl .
Another root can be set with the function odataR_set_root .
The most important function is odataR_get_table that downloads for a given table_id the main table and uses its subtables to decode dimensions (as Region
and Periods
). With the function odataR_get_meta the meta information of a table can be retrieved. Another important function is odataR_get_cat that gives an overview of the available tables in tibble (data_frame) format.
1 df = odataR_get_cat()
Retrieve the contents of the catalog
2 df = odataR_get_table(table_id="82935NED")
Convert table 82935NED
to a data.frame with all (two) dimensions decoded
3 df = odataR_get_meta(table_id="82935NED",metatype="DataProperties")
View the information about the fields in this table: the two dimensions are RegioS
and Perioden
4 df = odataR_get_table(table_id="82935NED",keepcode = c("RegioS","Perioden"))
Same as example2 but the coded version of both RegioS
and Perioden
are included
5 df = odataR_get_table(table_id="82935NED",keepcode = c("RegioS","Perioden"),
query = "?$filter=startswith(RegioS,'NL01')" )
Same as example4 but the OData server will only return rows where the value of RegioS starts with NL01
6 df = odataR_get_table(table_id="82935NED",
query = paste0("?$filter=startswith(RegioS,'NL01')",
"&$select=RegioS,Perioden,TotaleInvesteringen_1",
"&$skip=2&$top=3") )
Same as example5 but the OData server will only return the third, fourth and fifth row and the indicated fields (columns)
7 df = odataR_get_cat(query = paste0("?$filter=substringof('bevolking',tolower(ShortDescription))",
"&$select=Identifier,ShortTitle,ShortDescription,RecordCount,ColumnCount"))
Find in the catalog the tables with bevolking
(population) in the ShortDescription
field and restrict the returned fields to the ones specified with select
.
The $filter
, $select
, $skip
and $top
commands used in the examples 5 and further are elements of the query language for OData described in the OData protocol v4 for version 4 and the
OData protocol v3 for version 3.
The website of Statistics Netherlands is in progress of converting from version 3 to 4. Apart from the change in OData version the structure of the data is slightly changed. See New version CBS open data API (CCB) for details about the status of the conversion and function get_table_cbs_odata4
from package HOQCutil to read version 4 data.
The folder development_scripts contains three PDFs with extra information:
- odataR.pdf is the standard R help information in PDF format that is function oriented
- vignette_odataR.pdf describes how to use the package in a 'real world' case
- Reading_OData_with_MATLAB.pdf describes how to replay the example in the vignette in the MATLAB world.
Apart from these PDFs the folder also contains some devtools statements that were used to build the package.
NB this package (based on JSON) replaces odataR_old that was based on XML.
devtools::install_github("HanOostdijk/odataR",build_vignettes = T) # if ggplot2 already installed or ... devtools::install_github("HanOostdijk/odataR",build_vignettes = F) # if ggplot2 is not installed
- A introduction to OData : Introducing OData
- Details OData : OData - the best way to REST
- CBS (Statistics Netherlands) OData environment: Handleiding CBS Open Data Services (in Dutch)
- CBS (Statistics Netherlands) services: Open data (in Dutch)
To my knowledge two other packages concerning OData exist: