Demo

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(ODataQuery)

Introduction

Here I'll show some examples to use this package

Create service

service <- ODataQuery$new("https://services.odata.org/V4/TripPinServiceRW")
service$all()

Entity set

people_entity <- service$path("People")

# Get first page
people_entity$retrieve(count=TRUE)

# Get all pages
people_entity$select("UserName", "FirstName", "LastName")$all()

Singleton

russellwhyte <- people_entity$get("russellwhyte")
first_person <- people_entity$top(1)$one()
head(first_person)

russellwhyte_friends <- russellwhyte$path("Friends")
russellwhyte_friends$all()

Function call

get_nearest_airport <- service$func('GetNearestAirport')
get_nearest_airport(lat = 33, lon = -118)

Querying

people_query <- people_entity$
  top(5)$
  select('FirstName', 'LastName')$
  filter(Concurrency.gt = 500)$
  expand('Friends($count=true)')$
  orderby('LastName')

people_query$all()

Other endpoints

Statistics, the Netherlands

opendata_service <- ODataQuery$new("http://beta-odata4.cbs.nl/")
entity_81589NED  <- opendata_service$path("CBS", "81589NED", Observations")
dataset_81589NED <- entity_81589NED$all()

Northwind (OData v2)

Connecting with older OData v2 works, but some features have been changed.

northwind_service <- ODataQuery$new("https://services.odata.org/V2/Northwind/Northwind.svc/")
customer_entity <- northwind_service$path("Customers")
customer_entity$
  select("CompanyName", "Address", "Phone")$
  filter(Country.eq = "Germany", City.eq = "Berlin")

The Hague

So far, I haven't been able to figure out how their data model works, but at least we can connect to it.

denhaag_service <- ODataQuery$new("https://denhaag.incijfers.nl/jiveservices/odata/")
denhaag_service$path('DataSources')


Try the ODataQuery package in your browser

Any scripts or data that you put into this service are public.

ODataQuery documentation built on July 5, 2021, 5:09 p.m.