Package 'nsapi'

Title: Connect to the NS (Dutch Railways) API
Description: Access the NS api and download current departure times, disruptions and engineering work, the station list, and travel recommendations from station to station. All results will be returned as a 'data.frame'. NS (Nederlandse Spoorwegen; Dutch Railways) is the largest train travel provider in the Netherlands. for more information about the API itself see <https://www.ns.nl/en/travel-information/ns-api>. To use the API, and this package, you will need to obtain a username and password. More information about authentication and the use of the functions are described in the vignette.
Authors: Roel M. Hogervorst [cre, aut]
Maintainer: Roel M. Hogervorst <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0.9000
Built: 2024-08-27 02:32:21 UTC
Source: https://github.com/RMHogervorst/nsapi

Help Index


Are the username and password set?

Description

A function to see if your username and password are set for nsapi. Note that I have no clue if the password or username are correct, that is up to you.

Usage

check_ns_api_keys()

Details

For more details see the help vignette: vignette("basic_use_nsapi_package", package = "nsapi") and get your keys here: https://www.ns.nl/ews-aanvraagformulier/?0


Translate date and time into datetime stamp to use in api call

Description

The datetime stamp format might be a bit difficult to use. This helper function allows you to supply the date and time and a datetime character string comes out.

Usage

datetime(date, time)

Arguments

date

date in iso format (year-month-day): 2018-12-29 for example

time

time in standard format (HH:MM): 20:21

Details

For example if it is 21-08-2018, 15.21 hour in the Netherlands than you can add these two items into the function.

Examples

## Not run: 
get_travel_advise(
    fromStation = "Amsterdam Centraal",
    toStation = "Utrecht Centraal",
    dateTime = datetime("2018-08-21","15:21"),
    departure = TRUE
    )

## End(Not run)

Get up to date departures from a station

Description

Shows up to date departure times for a station. Displays all departing trains for the next hour. At least 10 departure times will be sent back and at least all the departure times for the next hour. https://www.ns.nl/en/travel-information/ns-api/documentation-up-to-date-departure-times.html.

Usage

get_departures(station)

Arguments

station

station names need to be in Dutch and the NS webservice also accepts short versions:f.i. Groningen or GN

Value

a dataframe with date time formatted as time in "Europe/Amsterdam" timezone.

a dataframe with departure times at this moment on the station you chose. Date time columns are formatted as time in "Europe/Amsterdam" timezone.

Examples

## Not run: 
get_departures("UT")

## End(Not run)

Get disruptions and engineering work

Description

These 3 functions call out to find out about disruptions and engineering on the tracks for the current time, for the next 2 weeks or a specific station.

Usage

get_disruptions_station(station)

get_current_disruptions()

get_scheduled_engineering_work()

Arguments

station

optional, station names need to be in Dutch and the NS webservice also accepts short versions:f.i. Groningen or GN

Details

  • current disruptions (=unscheduled disruptions + current engineering work)

These are all the disruptions of the railroad at this moment. So both unscheduled work and work and work that was scheduled and currently underway. Use get_current_disruptions()

  • scheduled engineering work(=scheduled engineering work)

Get all the scheduled engineering work for the next 2 weeks with get_scheduled_engineering_work(). This will exclude work that was unplanned.

  • current disruptions for a specific station (=unscheduled disruptions + current engineering work)

Use get_disruptions_station() and give a station name as argument.

https://www.ns.nl/en/travel-information/ns-api/documentation-disruptions-and-maintenance-work.html

Value

a dataframe with disruptions. Date time columns are formatted as time in "Europe/Amsterdam" timezone.

Functions

  • get_current_disruptions: current disruptions

  • get_scheduled_engineering_work: scheduled disruptions


Get a complete list of all the stations

Description

This function should not be called too often. The stations will probably not change a lot so it might be better to save it as a dataframe in your local environment for further use.

Usage

get_stationlist()

Details

The dataframe consists of all the Dutch stations, many German and Belgian stations and bigger stations in other countries in Europe. https://www.ns.nl/en/travel-information/ns-api/documentation-station-list.html


Get travel advise from one station to another station

Description

This is equivalent to the NS reisplanner, you give in a from and to station, the timestamp, if you want the time to be your departure or arrival time, and optionally if you have a NS year card (has effect on some travels).

Usage

get_travel_advise(fromStation, toStation, dateTime = NULL,
  departure = TRUE, yearCard = FALSE, hslAllowed = FALSE,
  previousAdvises = 4, nextAdvises = 4)

Arguments

fromStation

the station to start from, for instance "Rotterdam Centraal"

toStation

the station to end, for instance "Utrecht Centraal"

dateTime

defaults to current time, but you can use a different one: f.i. 2012-02-21T15:50, You can also use the datetime() function.

departure

is the datetime the start or end time? do you want to depart on that date or arrive, defaults to departure

yearCard

if you have a NS year card (jaarabonnement) some trips will be different

hslAllowed

use of the high speed train

previousAdvises

how many advices do you want before the time

nextAdvises

how many advises do you want after

Details

You can also specify how many trips before and after the chosen time you want to collect (defaults to 4, maximum is 5 before, and 5 after).

Some things to consider: station names need to be in Dutch but the NS webservice also accepts shortened versions: "Utrecht Centraal" and "ut" is apparently the same. Station names can be found with the get_stationlist() call.

Although the documentation https://www.ns.nl/en/travel-information/ns-api/documentation-travel-recommendations.html is in English, the returned values are all in Dutch. And I keep the results in Dutch.

Value

A dataframe with travel advises around your chosen date time. Date time columns are formatted as time in "Europe/Amsterdam" timezone.

Examples

## Not run: 
get_travel_advise("Amsterdam Centraal",
"Utrecht Centraal",dateTime = "2018-08-01T15:21",departure = TRUE)

## End(Not run)

NSapi package

Description

Access the NS api and download current departure times, disruptions and engineering work, the station list, and travel recommendations from station to station. All results will be returned as a 'data.frame'. NS (Nederlandse Spoorwegen; Dutch Railways) is the largest train travel provider in the Netherlands. for more information about the API itself see https://www.ns.nl/en/travel-information/ns-api. To use the API, and this package, you will need to obtain a username and password. More information about authentication and the use of the functions are described in the vignette.

Details

Implemented functions:

Image use: I have combined several images from the Noun project:

  • hands on circle: Data by Gregor Cresnar from the Noun Project:

  • train: railway by BomSymbols from the Noun Project

  • laptop Laptop by abdul karim from the Noun Project