nsapi

CRAN_latest_release_date license Project Status: Active – The project has reached a stable, usable state and is being actively developed. thanks-md lifecycle Travis-CI Build Status codecov

The Dutch National Railway service (NS; Nederlandse Spoorwegen) has an API where we can query for travel advise, see the current trains on a given station, see if there is any delays or work on the tracks and NS also provides a list with geolocation of all the stations.

The goal of nsapi is to make it easy to gather data from the NS API. The package returns data frames for every response.

an incredibly ugly logo for this package, we need a hexsticker!
an incredibly ugly logo for this package, we need a hexsticker!

Installation

You can NOT YET install the released version of nsapi from CRAN with:

install.packages("nsapi")

But you can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("RMHogervorst/nsapi")

Example

This is a basic example which shows you how you get travel information:

library(nsapi)
treinplanner <- get_travel_advise(
  fromStation = "Leiden Centraal", 
  toStation = "Utrecht Centraal",
  departure = TRUE,
  yearCard = TRUE,
  previousAdvises = 1, 
  nextAdvises = 1)
treinplanner
#>   Melding AantalOverstappen GeplandeReisTijd ActueleReisTijd
#> 1      NA                 1             0:55            0:58
#> 2      NA                 0             0:42            0:42
#> 3      NA                 1             1:00            1:00
#> 4      NA                 0             0:42            0:42
#>   VertrekVertraging AankomstVertraging Optimaal GeplandeVertrekTijd
#> 1              <NA>             +3 min    FALSE 2018-08-10 21:05:00
#> 2              <NA>               <NA>     TRUE 2018-08-10 21:22:00
#> 3              <NA>               <NA>    FALSE 2018-08-10 21:30:00
#> 4              <NA>               <NA>    FALSE 2018-08-10 21:52:00
#>    ActueleVertrekTijd GeplandeAankomstTijd ActueleAankomstTijd
#> 1 2018-08-10 21:05:00  2018-08-10 22:00:00 2018-08-10 22:03:00
#> 2 2018-08-10 21:22:00  2018-08-10 22:04:00 2018-08-10 22:04:00
#> 3 2018-08-10 21:30:00  2018-08-10 22:30:00 2018-08-10 22:30:00
#> 4 2018-08-10 21:52:00  2018-08-10 22:34:00 2018-08-10 22:34:00
#>         Status     ReisDeel
#> 1    VERTRAAGD c("NS", ....
#> 2 VOLGENS-PLAN NS, Inte....
#> 3 VOLGENS-PLAN c("NS", ....
#> 4 VOLGENS-PLAN NS, Inte....

FAQ

  1. What Can I do with the package?
  1. I’m getting a curl timeout!
  1. Error Bad request or HTTP 400
  1. How do I set a password and username?

Metadata

The package is MIT licensed although the information from NS is probably proprietary

codecoverage <- covr::package_coverage(path = ".",type = "tests")
print(codecoverage)
#> nsapi Coverage: 18.87%
#> R/api_calls_authentification.R: 4.84%
#> R/utils.R: 24.67%