Learn R Programming

trainR: An Interface to the National Rail Enquiries Systems

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")

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

Load trainR to your working environment:

library(trainR)

Arrivals board at Reading Station (RDG)

Generated on 2021-01-16 19:59:12.

rdg_arr <- trainR::GetArrBoardWithDetailsRequest("RDG")
print(rdg_arr)
#> Reading (RDG) Station Board on 2021-01-16 19:59:13
#> Time   From                                    Plat  Expected
#> 19:58  Great Malvern                           10A   19:55
#> 19:59  Basingstoke                             2     On time
#> 20:01  Didcot Parkway                          15    On time
#> 20:08  London Paddington                       8     On time
#> 20:11  London Waterloo                         6     On time
#> 20:13  London Paddington                       14    On time
#> 20:16  London Paddington                       9     On time
#> 20:21  Bedwyn                                  11    On time
#> 20:27  Basingstoke                             2     On time
#> Time   From                                    Plat  Expected
#> 20:13  Swindon (Wilts)                         BUS   On time

Departures board at Reading Station (RDG)

Generated on 2021-01-16 19:59:13.

rdg_dep <- trainR::GetDepBoardWithDetailsRequest("RDG")
print(rdg_dep)
#> Reading (RDG) Station Board on 2021-01-16 19:59:13
#> Time   To                                      Plat  Expected
#> 20:00  London Paddington                       10A   On time
#> 20:01  Redhill                                 6     On time
#> 20:10  Swansea                                 8     On time
#> 20:12  London Waterloo                         4     On time
#> 20:14  Newbury                                 1     On time
#> 20:15  Ealing Broadway                         15    On time
#> 20:15  Manchester Piccadilly                   13    On time
#> 20:19  Great Malvern                           9     On time
#> 20:22  Ealing Broadway                         14    On time
#> Time   To                                      Plat  Expected
#> 20:20  Swindon (Wilts)                         BUS   On time

Acknowledgements

Access to the data feeds it is only possible thanks to the National Rail Enquiries. This package is just a tool to facilitate access to the data. For more information about the available data feeds, visit https://www.nationalrail.co.uk.

Copy Link

Version

Install

install.packages('trainR')

Monthly Downloads

203

Version

0.0.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Roberto Villegas-Diaz

Last Published

January 20th, 2021

Functions in trainR (0.0.1)

extract

Extract data from XML request
get_calling_points

Obtain previous calling points
print_board

Print arrivals/departures board
print

Print Values
station_codes

National Rail Enquiries (NRE) Station Codes dataset
validate

Validate output from request
set_token

Configure user's token
request

Submit a SOAP XML request
GetServiceDetailsRequest

Get service details
GetArrBoardWithDetailsRequest

Get all public arrivals
get_location

Get the full station name
get_token

Get user's token
GetDepBoardWithDetailsRequest

Get all public departures
GetArrDepBoardWithDetailsRequest

Get all public arrivals and departures
%>%

Pipe operator
is_valid_crs

Validate station code (CRS)