The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

trainR: An Interface to the National Rail Enquiries Systems logo

R build status

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.

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.