Git Product home page Git Product logo

naptanr's Introduction

naptanr

Lifecycle: experimental CRAN status R-CMD-check

The goal of naptanr is to allow easy interface between the National Public Transport Access Nodes (NaPTAN) API and R. The NaPTAN dataset provides the location and type of every location you can join or leave public transport in England, Scotland and Wales. Further details and documentation on the NaPTAN API can be found here.

Installation

You can install the development version of naptanr from GitHub with:

# install.packages("devtools")
devtools::install_github("department-for-transport-public/naptanr")

Usage

naptanr has several functions designed to make it easy for you to interrogate the NaPTAN API and receive the results as an R dataframe object.

Returning Naptan results from ATCO codes

The call_naptan() function allows you to request data for one or more ATCO area codes.

Calling this function with no arguments returns a full data frame of all results currently stored in Naptan.

You can also specify the area you would like to see results for by using the atco argument in this function. You can give a single three-digit ATCO code as a string, or multiple ATCO codes as a vector of strings, e.g.

library(naptanr)

## Single ATCO code
call_naptanr(atco = "050")

## Multiple ATCO codes
call_naptanr(atco = c("050", "290"))

If you provide one or more invalid ATCO codes, the function will return an error and let you know which ATCO codes are incorrect.

Returning NaPTAN results from region name

Functions are also available to help you if you don't know the ATCO code of the region(s) you're interested in. The lookup_atco_codes() function returns a lookup table of area names and ATCO Area Codes. Calling this function without arguments returns a full list of all available ATCO area codes.

If you'd like to filter this list down, the function offers several arguments to do this. You can use the area_name argument to specify the full or partial name of the area you're interested in, for example:

library(naptanr)

## Returns area code for Cornwall only
lookup_atco_codes(area_name = "cornwall")

## Returns area code for all areas containing the partial string "west"
lookup_atco_codes(area_name = "west")

This search operates via regular expression and is not case sensitive.

You can also return the area codes for a single country using the country argument. Specify "ENG", "SCO" or "WAL" to return values for England, Scotland or Wales respectively.

library(naptanr)

## Returns area codes for all areas in Wales 
lookup_atco_codes(country = "WAL")

You can also use the same type of lookup to return NaPTAN data directly using the call_naptan_region() function. Passing a full or partial area name to the region_string argument returns results for all areas which match this lookup.

library(naptanr)

## Returns results for all areas containing the string "yorkshire"  
call_naptan_region(region_string = "yorkshire")

naptanr's People

Contributors

dipad-fran-bryden avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.