Package 'trainR'

Title: An Interface to the National Rail Enquiries Systems
Description: 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>.
Authors: Roberto Villegas-Diaz [aut, cre]
Maintainer: Roberto Villegas-Diaz <[email protected]>
License: MIT + file LICENSE
Version: 0.0.1.9000
Built: 2024-11-21 03:19:49 UTC
Source: https://github.com/villegar/trainr

Help Index


Get CRS code

Description

Get CRS code from a string with the station name.

Usage

get_crs(station, ...)

Arguments

station

String with the station name, partial names are allowed.

...

Arguments passed on to base::grep

ignore.case

if FALSE, the pattern matching is case sensitive and if TRUE, case is ignored during matching.

perl

logical. Should Perl-compatible regexps be used?

value

if FALSE, a vector containing the (integer) indices of the matches determined by grep is returned, and if TRUE, a vector containing the matching elements themselves is returned.

fixed

logical. If TRUE, pattern is a string to be matched as is. Overrides all conflicting arguments.

useBytes

logical. If TRUE the matching is done byte-by-byte rather than character-by-character. See ‘Details’.

invert

logical. If TRUE return indices or values for elements that do not match.

Value

Vector of strings with the matched CRS codes, or NULL if no match is found.

Examples

trainR::get_crs("London")
trainR::get_crs("Manchester")
trainR::get_crs("manchester", ignore.case = TRUE)

Get user's token

Description

Get user's token to access the National Rail Enquiries (NRE) data feeds.

Usage

get_token(ENV = "NRE")

Arguments

ENV

String with environment variable containing the token to access the NRE data feeds (default = "NRE").

Value

String with token.


Get all public arrivals

Description

Get all public arrivals for the supplied CRS code within a defined time window.

Usage

GetArrBoardRequest(
  crs,
  filterCrs = NA,
  filterType = "from",
  numRows = 150,
  timeOffset = 0,
  timeWindow = 120,
  token = get_token(),
  url = "https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ldb11.asmx",
  verbose = FALSE
)

Arguments

crs

(string, 3 characters, alphabetic): The CRS code of the location for which the request is being made.

filterCrs

(string, 3 characters, alphabetic): The CRS code of either an origin or destination location to filter in. Optional.

filterType

(string, either "from" or "to"): The type of filter to apply. Filters services to include only those originating or terminating at the filterCrs location. Defaults to "to".

numRows

(integer, between 0 and 150 exclusive): The number of services to return in the resulting station board.

timeOffset

(integer, between -120 and 120 exclusive): An offset in minutes against the current time to provide the station board for. Defaults to 0.

timeWindow

(integer, between -120 and 120 exclusive): How far into the future in minutes, relative to timeOffset, to return services for. Defaults to 120.

token

Token to access the data feed. The token can be obtained at http://realtime.nationalrail.co.uk/OpenLDBWSRegistration/.

url

Data feed source URL.

verbose

Boolean flag to indicate whether or not to show status messages.

Value

Tibble with arrival records. Each column is described below:

generatedAt

The time at which the station board was generated.

locationName

The name of the location that the station board is for.

crs

The CRS code of the location that the station board is for.

filterLocationName

If a filter was requested, the location name of the filter location.

filtercrs

If a filter was requested, the CRS code of the filter location.

filterType

If a filter was requested, the type of filter.

nrccMessages

An optional list of textual messages that should be displayed with the station board. The message may include embedded and XML encoded HTML-like hyperlinks and paragraphs. The messages are typically used to display important disruption information that applies to the location that the station board was for. Any embedded <p> tags are used to force a new-line in the output. Embedded <a> tags allow links to external web pages that may provide more information. Output channels that do not support HTML should strip out the <a> tags and just leave the enclosed text.

platformAvailable

An optional value that indicates if platform information is available. If this value is present with the value "true" then platform information will be returned in the service lists. If this value is not present, or has the value "false", then the platform "heading" should be suppressed in the user interface for this station board.

areServicesAvailable

An optional value that indicates if services are currently available for this station board. If this value is present with the value "false" then no services will be returned in the service lists. This value may be set, for example, if access to a station has been closed to the public at short notice, even though the scheduled services are still running. It would be usual in such cases for one of the nrccMessages to describe why the list of services has been suppressed.

trainServices

A list of ServiceItem object for each services of the relevant type that is to appear on the station board. May contain zero items, or may not be present at all.

busServices

A list of ServiceItem object for each services of the relevant type that is to appear on the station board. May contain zero items, or may not be present at all.

ferryServices

A list of ServiceItem object for each services of the relevant type that is to appear on the station board. May contain zero items, or may not be present at all.

Source

Documentation for the Live Departure Boards Web Service (LDBWS / OpenLDBWS): http://lite.realtime.nationalrail.co.uk/openldbws/

See Also

Other OpenLDBSVWS requests: GetArrBoardWithDetailsRequest(), GetArrDepBoardWithDetailsRequest(), GetDepBoardRequest(), GetDepBoardWithDetailsRequest(), GetServiceDetailsRequest()

Examples

## Not run: 
rdg_arr <- trainR::GetArrBoardRequest("RDG")
rdg_arr <- trainR::GetArrBoardRequest("RDG", filterCrs = "BRI")
trainR::print(rdg_arr)

## End(Not run)

Get all public arrivals

Description

Get all public arrivals for the supplied CRS code within a defined time window, including service details.

Usage

GetArrBoardWithDetailsRequest(
  crs,
  filterCrs = NA,
  filterType = "from",
  numRows = 150,
  timeOffset = 0,
  timeWindow = 120,
  token = get_token(),
  url = "https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ldb11.asmx",
  verbose = FALSE
)

Arguments

crs

(string, 3 characters, alphabetic): The CRS code of the location for which the request is being made.

filterCrs

(string, 3 characters, alphabetic): The CRS code of either an origin or destination location to filter in. Optional.

filterType

(string, either "from" or "to"): The type of filter to apply. Filters services to include only those originating or terminating at the filterCrs location. Defaults to "to".

numRows

(integer, between 0 and 150 exclusive): The number of services to return in the resulting station board.

timeOffset

(integer, between -120 and 120 exclusive): An offset in minutes against the current time to provide the station board for. Defaults to 0.

timeWindow

(integer, between -120 and 120 exclusive): How far into the future in minutes, relative to timeOffset, to return services for. Defaults to 120.

token

Token to access the data feed. The token can be obtained at http://realtime.nationalrail.co.uk/OpenLDBWSRegistration/.

url

Data feed source URL.

verbose

Boolean flag to indicate whether or not to show status messages.

Value

Tibble with arrival records. Each column is described below:

generatedAt

The time at which the station board was generated.

locationName

The name of the location that the station board is for.

crs

The CRS code of the location that the station board is for.

filterLocationName

If a filter was requested, the location name of the filter location.

filtercrs

If a filter was requested, the CRS code of the filter location.

filterType

If a filter was requested, the type of filter.

nrccMessages

An optional list of textual messages that should be displayed with the station board. The message may include embedded and XML encoded HTML-like hyperlinks and paragraphs. The messages are typically used to display important disruption information that applies to the location that the station board was for. Any embedded <p> tags are used to force a new-line in the output. Embedded <a> tags allow links to external web pages that may provide more information. Output channels that do not support HTML should strip out the <a> tags and just leave the enclosed text.

platformAvailable

An optional value that indicates if platform information is available. If this value is present with the value "true" then platform information will be returned in the service lists. If this value is not present, or has the value "false", then the platform "heading" should be suppressed in the user interface for this station board.

areServicesAvailable

An optional value that indicates if services are currently available for this station board. If this value is present with the value "false" then no services will be returned in the service lists. This value may be set, for example, if access to a station has been closed to the public at short notice, even though the scheduled services are still running. It would be usual in such cases for one of the nrccMessages to describe why the list of services has been suppressed.

trainServices

A list of ServiceItem object for each services of the relevant type that is to appear on the station board. May contain zero items, or may not be present at all.

busServices

A list of ServiceItem object for each services of the relevant type that is to appear on the station board. May contain zero items, or may not be present at all.

ferryServices

A list of ServiceItem object for each services of the relevant type that is to appear on the station board. May contain zero items, or may not be present at all.

Source

Documentation for the Live Departure Boards Web Service (LDBWS / OpenLDBWS): http://lite.realtime.nationalrail.co.uk/openldbws/

See Also

Other OpenLDBSVWS requests: GetArrBoardRequest(), GetArrDepBoardWithDetailsRequest(), GetDepBoardRequest(), GetDepBoardWithDetailsRequest(), GetServiceDetailsRequest()

Examples

## Not run: 
rdg_arr <- trainR::GetArrBoardWithDetailsRequest("RDG")
rdg_arr <- trainR::GetArrBoardWithDetailsRequest("RDG", filterCrs = "BRI")
trainR::print(rdg_arr)

## End(Not run)

Get all public arrivals and departures

Description

Get all public arrivals and departures for the supplied CRS code within a defined time window, including service details.

Usage

GetArrDepBoardWithDetailsRequest(
  crs,
  filterCrs = NA,
  filterType = "from",
  numRows = 150,
  timeOffset = 0,
  timeWindow = 120,
  token = get_token(),
  url = "https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ldb11.asmx",
  verbose = FALSE
)

Arguments

crs

(string, 3 characters, alphabetic): The CRS code of the location for which the request is being made.

filterCrs

(string, 3 characters, alphabetic): The CRS code of either an origin or destination location to filter in. Optional.

filterType

(string, either "from" or "to"): The type of filter to apply. Filters services to include only those originating or terminating at the filterCrs location. Defaults to "to".

numRows

(integer, between 0 and 150 exclusive): The number of services to return in the resulting station board.

timeOffset

(integer, between -120 and 120 exclusive): An offset in minutes against the current time to provide the station board for. Defaults to 0.

timeWindow

(integer, between -120 and 120 exclusive): How far into the future in minutes, relative to timeOffset, to return services for. Defaults to 120.

token

Token to access the data feed. The token can be obtained at http://realtime.nationalrail.co.uk/OpenLDBWSRegistration/.

url

Data feed source URL.

verbose

Boolean flag to indicate whether or not to show status messages.

Value

Tibble with arrival and departure records. Each column is described below:

generatedAt

The time at which the station board was generated.

locationName

The name of the location that the station board is for.

crs

The CRS code of the location that the station board is for.

filterLocationName

If a filter was requested, the location name of the filter location.

filtercrs

If a filter was requested, the CRS code of the filter location.

filterType

If a filter was requested, the type of filter.

nrccMessages

An optional list of textual messages that should be displayed with the station board. The message may include embedded and XML encoded HTML-like hyperlinks and paragraphs. The messages are typically used to display important disruption information that applies to the location that the station board was for. Any embedded <p> tags are used to force a new-line in the output. Embedded <a> tags allow links to external web pages that may provide more information. Output channels that do not support HTML should strip out the <a> tags and just leave the enclosed text.

platformAvailable

An optional value that indicates if platform information is available. If this value is present with the value "true" then platform information will be returned in the service lists. If this value is not present, or has the value "false", then the platform "heading" should be suppressed in the user interface for this station board.

areServicesAvailable

An optional value that indicates if services are currently available for this station board. If this value is present with the value "false" then no services will be returned in the service lists. This value may be set, for example, if access to a station has been closed to the public at short notice, even though the scheduled services are still running. It would be usual in such cases for one of the nrccMessages to describe why the list of services has been suppressed.

trainServices

A list of ServiceItem object for each services of the relevant type that is to appear on the station board. May contain zero items, or may not be present at all.

busServices

A list of ServiceItem object for each services of the relevant type that is to appear on the station board. May contain zero items, or may not be present at all.

ferryServices

A list of ServiceItem object for each services of the relevant type that is to appear on the station board. May contain zero items, or may not be present at all.

Source

Documentation for the Live Departure Boards Web Service (LDBWS / OpenLDBWS): http://lite.realtime.nationalrail.co.uk/openldbws/

See Also

Other OpenLDBSVWS requests: GetArrBoardRequest(), GetArrBoardWithDetailsRequest(), GetDepBoardRequest(), GetDepBoardWithDetailsRequest(), GetServiceDetailsRequest()

Examples

## Not run: 
rdg<- trainR::GetArrDepBoardWithDetailsRequest("RDG")
rdg <- trainR::GetArrDepBoardWithDetailsRequest("RDG", filterCrs = "BRI")
trainR::print(rdg)

## End(Not run)

Get all public departures

Description

Get all public departures for the supplied CRS code within a defined time window.

Usage

GetDepBoardRequest(
  crs,
  filterCrs = NA,
  filterType = "to",
  numRows = 150,
  timeOffset = 0,
  timeWindow = 120,
  token = get_token(),
  url = "https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ldb11.asmx",
  verbose = FALSE
)

Arguments

crs

(string, 3 characters, alphabetic): The CRS code of the location for which the request is being made.

filterCrs

(string, 3 characters, alphabetic): The CRS code of either an origin or destination location to filter in. Optional.

filterType

(string, either "from" or "to"): The type of filter to apply. Filters services to include only those originating or terminating at the filterCrs location. Defaults to "to".

numRows

(integer, between 0 and 150 exclusive): The number of services to return in the resulting station board.

timeOffset

(integer, between -120 and 120 exclusive): An offset in minutes against the current time to provide the station board for. Defaults to 0.

timeWindow

(integer, between -120 and 120 exclusive): How far into the future in minutes, relative to timeOffset, to return services for. Defaults to 120.

token

Token to access the data feed. The token can be obtained at http://realtime.nationalrail.co.uk/OpenLDBWSRegistration/.

url

Data feed source URL.

verbose

Boolean flag to indicate whether or not to show status messages.

Value

Tibble with departure records. Each column is described below:

generatedAt

The time at which the station board was generated.

locationName

The name of the location that the station board is for.

crs

The CRS code of the location that the station board is for.

filterLocationName

If a filter was requested, the location name of the filter location.

filtercrs

If a filter was requested, the CRS code of the filter location.

filterType

If a filter was requested, the type of filter.

nrccMessages

An optional list of textual messages that should be displayed with the station board. The message may include embedded and XML encoded HTML-like hyperlinks and paragraphs. The messages are typically used to display important disruption information that applies to the location that the station board was for. Any embedded <p> tags are used to force a new-line in the output. Embedded <a> tags allow links to external web pages that may provide more information. Output channels that do not support HTML should strip out the <a> tags and just leave the enclosed text.

platformAvailable

An optional value that indicates if platform information is available. If this value is present with the value "true" then platform information will be returned in the service lists. If this value is not present, or has the value "false", then the platform "heading" should be suppressed in the user interface for this station board.

areServicesAvailable

An optional value that indicates if services are currently available for this station board. If this value is present with the value "false" then no services will be returned in the service lists. This value may be set, for example, if access to a station has been closed to the public at short notice, even though the scheduled services are still running. It would be usual in such cases for one of the nrccMessages to describe why the list of services has been suppressed.

trainServices

A list of ServiceItem object for each services of the relevant type that is to appear on the station board. May contain zero items, or may not be present at all.

busServices

A list of ServiceItem object for each services of the relevant type that is to appear on the station board. May contain zero items, or may not be present at all.

ferryServices

A list of ServiceItem object for each services of the relevant type that is to appear on the station board. May contain zero items, or may not be present at all.

Source

Documentation for the Live Departure Boards Web Service (LDBWS / OpenLDBWS): http://lite.realtime.nationalrail.co.uk/openldbws/

See Also

Other OpenLDBSVWS requests: GetArrBoardRequest(), GetArrBoardWithDetailsRequest(), GetArrDepBoardWithDetailsRequest(), GetDepBoardWithDetailsRequest(), GetServiceDetailsRequest()

Examples

## Not run: 
rdg_dep <- trainR::GetDepBoardRequest("RDG")
rdg_dep <- trainR::GetDepBoardRequest("RDG", filterCrs = "BRI")
trainR::print(rdg_dep)

## End(Not run)

Get all public departures

Description

Get all public departures for the supplied CRS code within a defined time window, including service details.

Usage

GetDepBoardWithDetailsRequest(
  crs,
  filterCrs = NA,
  filterType = "to",
  numRows = 150,
  timeOffset = 0,
  timeWindow = 120,
  token = get_token(),
  url = "https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ldb11.asmx",
  verbose = FALSE
)

Arguments

crs

(string, 3 characters, alphabetic): The CRS code of the location for which the request is being made.

filterCrs

(string, 3 characters, alphabetic): The CRS code of either an origin or destination location to filter in. Optional.

filterType

(string, either "from" or "to"): The type of filter to apply. Filters services to include only those originating or terminating at the filterCrs location. Defaults to "to".

numRows

(integer, between 0 and 150 exclusive): The number of services to return in the resulting station board.

timeOffset

(integer, between -120 and 120 exclusive): An offset in minutes against the current time to provide the station board for. Defaults to 0.

timeWindow

(integer, between -120 and 120 exclusive): How far into the future in minutes, relative to timeOffset, to return services for. Defaults to 120.

token

Token to access the data feed. The token can be obtained at http://realtime.nationalrail.co.uk/OpenLDBWSRegistration/.

url

Data feed source URL.

verbose

Boolean flag to indicate whether or not to show status messages.

Value

Tibble with departure records. Each column is described below:

generatedAt

The time at which the station board was generated.

locationName

The name of the location that the station board is for.

crs

The CRS code of the location that the station board is for.

filterLocationName

If a filter was requested, the location name of the filter location.

filtercrs

If a filter was requested, the CRS code of the filter location.

filterType

If a filter was requested, the type of filter.

nrccMessages

An optional list of textual messages that should be displayed with the station board. The message may include embedded and XML encoded HTML-like hyperlinks and paragraphs. The messages are typically used to display important disruption information that applies to the location that the station board was for. Any embedded <p> tags are used to force a new-line in the output. Embedded <a> tags allow links to external web pages that may provide more information. Output channels that do not support HTML should strip out the <a> tags and just leave the enclosed text.

platformAvailable

An optional value that indicates if platform information is available. If this value is present with the value "true" then platform information will be returned in the service lists. If this value is not present, or has the value "false", then the platform "heading" should be suppressed in the user interface for this station board.

areServicesAvailable

An optional value that indicates if services are currently available for this station board. If this value is present with the value "false" then no services will be returned in the service lists. This value may be set, for example, if access to a station has been closed to the public at short notice, even though the scheduled services are still running. It would be usual in such cases for one of the nrccMessages to describe why the list of services has been suppressed.

trainServices

A list of ServiceItem object for each services of the relevant type that is to appear on the station board. May contain zero items, or may not be present at all.

busServices

A list of ServiceItem object for each services of the relevant type that is to appear on the station board. May contain zero items, or may not be present at all.

ferryServices

A list of ServiceItem object for each services of the relevant type that is to appear on the station board. May contain zero items, or may not be present at all.

Source

Documentation for the Live Departure Boards Web Service (LDBWS / OpenLDBWS): http://lite.realtime.nationalrail.co.uk/openldbws/

See Also

Other OpenLDBSVWS requests: GetArrBoardRequest(), GetArrBoardWithDetailsRequest(), GetArrDepBoardWithDetailsRequest(), GetDepBoardRequest(), GetServiceDetailsRequest()

Examples

## Not run: 
rdg_dep <- trainR::GetDepBoardWithDetailsRequest("RDG")
rdg_dep <- trainR::GetDepBoardWithDetailsRequest("RDG", filterCrs = "BRI")
trainR::print(rdg_dep)

## End(Not run)

Get service details

Description

Get the service details for a specific service identified by a station board. These details are supplied relative to the station board from which the serviceID field value was generated. Service details are only available while the service appears on the station board from which it was obtained. This is normally for two minutes after it is expected to have departed, or after a terminal arrival. If a request is made for a service that is no longer available then a NULL value is returned.

Usage

GetServiceDetailsRequest(
  serviceID,
  token = get_token(),
  url = "https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ldb11.asmx",
  verbose = FALSE
)

Arguments

serviceID

(string): The LDBWS service ID of the service to request the details of. The service ID is obtained from a service listed in a StationBoard object returned from any other request.

token

Token to access the data feed. The token can be obtained at http://realtime.nationalrail.co.uk/OpenLDBWSRegistration/.

url

Data feed source URL.

verbose

Boolean flag to indicate whether or not to show status messages.

Value

Tibble with departure records.

See Also

Other OpenLDBSVWS requests: GetArrBoardRequest(), GetArrBoardWithDetailsRequest(), GetArrDepBoardWithDetailsRequest(), GetDepBoardRequest(), GetDepBoardWithDetailsRequest()


Configure user's token

Description

Configure user's token to access the National Rail Enquiries (NRE) data feeds.

Usage

set_token()

Details

To obtain an access token, you must complete the registration form found at http://realtime.nationalrail.co.uk/OpenLDBWSRegistration/.

Value

Nothing, helper function to set up environment variable.


National Rail Enquiries (NRE) Station Codes dataset

Description

A dataset containing information of 2579 British National Rail Enquiries (NRE) station 3 letter alpha (CRS) codes.

Usage

data(station_codes)

Format

A data frame with 2579 rows and 2 variables:

name

Station name.

crs

Station code.

Author(s)

National Rail Enquiries (NRE)

Source

https://www.nationalrail.co.uk/stations_destinations/48541.aspx


Store object to disk

Description

Experimental lifecycle

Usage

store(x, ...)

## S3 method for class 'StationBoard'
store(x, ..., file)

## S3 method for class 'busServices'
store(x, ..., wb)

## S3 method for class 'ferryServices'
store(x, ..., wb)

## S3 method for class 'trainServices'
store(x, ..., wb)

## S3 method for class 'CallingPoints'
store(x, ..., wb, serviceID)

## S3 method for class 'previousCallingPoints'
store(x, ..., wb, serviceID)

## S3 method for class 'subsequentCallingPoints'
store(x, ..., wb, serviceID)

Arguments

x

Data.

...

Optional parameters.

file

String with filename and path.

wb

Workbook object, created with openxlsx::createWorkbook.

serviceID

(string): The LDBWS service ID of the service to request the details of. The service ID is obtained from a service listed in a StationBoard object returned from any other request.

Details

The goal of this generic is to facilitate storing data retrieved from arrival and departure boards. Each request has multiple parts that should be stored individually (e.g. Excel Workbook or individual CSV files).

Value

Nothing, call for its side effect.

Examples

## Not run: 
`%>%` <- magrittr::`%>%`
pad <- trainR::GetArrBoardWithDetailsRequest("PAD")
pad %>%
  trainR::store(file = "arrivals-PAD.xlsx")

# Delete test file
unlink("arrivals-PAD.xlsx")

## End(Not run)