trainR: An Interface to the National Rail Enquiries Systems

logo

The goal of trainR is to provide a simple interface to the National Rail Enquiries (NRE) systems. There are few data feeds available, the simplest of them is Darwin, which provides real-time arrival and departure predictions, platform numbers, delay estimates, schedule changes and cancellations. Other data feeds provide historical data, Historic Service Performance (HSP), and much more. trainR simplifies the data retrieval, so that the users can focus on their analyses. For more details visit https://www.nationalrail.co.uk/46391.aspx.

Installation

You can install the released version of trainR from CRAN with:

install.packages("trainR")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("villegar/trainR", "dev")

Setup

Before starting to retrieve data from the NRE data feeds, you must obtain an access token. Visit the following website for details: http://realtime.nationalrail.co.uk/OpenLDBWSRegistration/

Once you have received your access token, you have to store it in the .Renviron file; this can be done by executing the following command:

trainR::set_token()

This will open a text file, .Renviron, add a new line at the end (as follows):

NRE="<token>"

<token> should be replaced by the access token obtained from the NRE. Save the changes and restart your R session.

You only need to perform this configuration once.

Example (Last rendered on 2022-10-01 20:04)

Load trainR to your working environment:

library(trainR)

Arrivals board at Reading Station (RDG)

rdg_arr <- trainR::GetArrBoardRequest("RDG")
print(rdg_arr)
## Reading (RDG) Station Board on 2022-10-01 20:04:33

Departures board at Reading Station (RDG)

rdg_dep <- trainR::GetDepBoardRequest("RDG")
print(rdg_dep)
## Reading (RDG) Station Board on 2022-10-01 20:04:36