get_table_cbs_odata4: Retrieving CBS Odata4 table data

get_table_cbs_odata4R Documentation

Retrieving CBS Odata4 table data

Description

The function get_table_cbs_odata4 can be used to retrieve data or information from the new CBS ('Centraal Bureau voor de Statistiek' or 'Statistics Netherlands') Odata4 data infrastructure. The general OData4 protocol is described in http://docs.oasis-open.org/odata/odata/v4.0/odata-v4.0-part1-protocol.html and the part that is implemented by CBS in https://beta-dataportal.cbs.nl/

The function get_table_cbs_odata4_GET handles the network IO for the get_table_cbs_odata4 function but can also be used stand-alone.

Usage

get_table_cbs_odata4(
  root = NULL,
  table_id = NULL,
  subtable = NULL,
  query = NULL,
  verbose = FALSE,
  encode = TRUE,
  odata_root = "https://odata4.cbs.nl",
  odata_cat = "CBS",
  restype = "",
  error_msg = TRUE
)

get_table_cbs_odata4_GET(url, restype = "", error_msg = TRUE)

Arguments

root

Character string with the root for the url. When specified odata_root and odata_cat are not used

table_id

Character string identifying table for which information will be returned. When table_id == NULL catalog information will be returned.

subtable

Character string indicating subtable for which information will be returned. When subtable == NULL information about the available subtables will be returned.

query

Character string with an OData4 query. See http://docs.oasis-open.org/odata/odata/v4.0/odata-v4.0-part1-protocol.html for the general OData4 query possibilities and https://acc-ccb.cbs.nl/implement.html for the subset of the CBS implementation.

verbose

Boolean indicating if the generated url should be shown as a message.

encode

Boolean indicating if the query has to be encode by URLencode.

odata_root

Character string with the root for the url.

odata_cat

Character string with the catalog identifier.

restype

Character string indicating if the query has to return a data.frame or list (when ''), a httr response object (when resp) or a JSON string (when json).

error_msg

Boolean indicating if the query has to return a more extensive error message. Useful for debugging.

url

Character string with url that will be passed to GET function without further encoding. It is assumed that a json result can be returned.

Value

if not succesful a character string with an error message. If succesful the contents is regarded as a json object and translated to a data.frame or list when possible. However if restype='resp' the result is a httr response object and when restype='json' the JSON string is not converted

Additional example

See https://gist.github.com/HanOostdijk/787e9724dcd63735a431bcd16cbd18a0 for an analysis done with get_table_cbs_odata4. The resulting PDF file can be found in https://www.hanoostdijk.nl/hugo/opendata_beta_versie4_dec2018_20181225.pdf .

Examples

## Not run: 
t1=get_table_cbs_odata4()
t1=get_table_cbs_odata4(subtable="Datasets")
t1=get_table_cbs_odata4(subtable="Catalogs")
t1=get_table_cbs_odata4(table_id="82931NED")
t1=get_table_cbs_odata4(table_id="82931NED",subtable="Dimensions")
t1=get_table_cbs_odata4(table_id="82931NED",subtable="Properties")
t1=get_table_cbs_odata4(table_id="82931NED",subtable="Observations",query="$skip=1&$top=2")
t1=get_table_cbs_odata4(table_id="82931NED",subtable="Observations",query="$count")
t1=get_table_cbs_odata4(table_id="82931NED",subtable="Observations",query="(7)")

myurl = "https://beta-odata4.cbs.nl/CBS/82931NED/Observations?$format=json&$skip=1&$top=2"
t1=get_table_cbs_odata4_GET(myurl)
t1=get_table_cbs_odata4_GET(myurl,restype='resp')
t1=get_table_cbs_odata4_GET(myurl,restype='json')
t1=get_table_cbs_odata4_GET(myurl,error_msg=T)

## End(Not run)

HanOostdijk/HOQCutil documentation built on July 28, 2023, 5:56 p.m.