Learn R Programming

nhlapi

A minimum-dependency R interface to the NHL API.

{nhlapi} is an R package that provides functionality to retrieve and process the data exposed by the open NHL API. This includes information on players, teams, games, tournaments, drafts, standings, schedules and other endpoints. A lower-level interface to access the data via URLs directly is also provided. See below for a full list of endpoints.

Installation

You can install {nhlapi} from CRAN:

install.packages("nhlapi")

You can also install the latest development version from the master branch on GitHub using the {remotes} or {devtools} packages:

# With remotes
remotes::install_github("jozefhajnala/nhlapi")

# Or with devtools
devtools::install_github("jozefhajnala/nhlapi")

Use and develop with Docker

The Docker image jozefhajnala/nhlapi has RStudio and a set of useful packages for both interactive use of the {nhlapi} package and its development.

Running the following command and opening localhost:8787 in a web browser should open RStudio with a setup ready for analysis and development. Login user is rstudio and password is pass:

# Password can be changed by changing the PASSWORD option below:
# If you need root permissions, add `-e ROOT=true`
docker run --rm -p 8787:8787 -e PASSWORD=pass jozefhajnala/nhlapi

Usage

We retrieve the data from the NHL API by calling the functions exported by the {nhlapi} package. They start with nhl_ so you can easily find them with auto-complete in your favorite editor:

In-depth look at use

The package's vignettes provide a more detailed overview of some of the functionality:

Implemented API endpoints

Major endpoints

  • Teams

    • Team Metadata nhl_teams()
    • Team Rosters nhl_teams_rosters()
    • Team Schedules nhl_teams_shedule_next(), nhl_teams_shedule_previous()
    • Team Stats nhl_teams_stats()
  • People (Players)

    • Players metadata nhl_players
    • Players season/playoff stats nhl_players_seasons()
    • Players all season stats nhl_players_allseasons()
  • Games

    • Games content nhl_games_content()
    • Games full live feed nhl_games_feed()
    • Games box score info nhl_games_boxscore()
    • Games line score infonhl_games_linescore()
  • Tournaments

    • Playoffs nhl_tournaments_playoffs()
    • Olympics nhl_tournaments_olympics()
    • World Cups nhl_tournaments_worldcups()
  • Schedule

    • Generic API with all parameters nhl_schedule()
    • Today nhl_schedule_today()
    • Custom seasons nhl_schedule_seasons()
    • Custom date ranges nhl_schedule_date_range()
  • Standings nhl_standings()

Minor endpoints

  • Divisions nhl_divisions()
  • Conferences nhl_conferences()
  • Drafts nhl_drafts()
  • Seasons nhl_seasons()
  • Awards nhl_awards()
  • Venues nhl_venues()
  • Draft prospects nhl_draft_prospects()

Metadata endpoints

  • Game Types nhl_md_game_types()
  • Game Statuses nhl_md_game_statuses()
  • Play Types nhl_md_play_types()
  • Tournament Types nhl_md_tournament_types()
  • Standings Types nhl_md_standings_types()
  • Stats Types nhl_md_stat_types()
  • Event Types nhl_md_event_types()

Acknowledgments

Thanks go to Drew Hynes for documenting this so well on GitLab.

Copyright message

NHL and the NHL Shield are registered trademarks of the National Hockey League. NHL and NHL team marks are the property of the NHL and its teams. © NHL 2021. All Rights Reserved.

Copy Link

Version

Install

install.packages('nhlapi')

Monthly Downloads

180

Version

0.1.4

License

AGPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Jozef Hajnala

Last Published

February 20th, 2021

Functions in nhlapi (0.1.4)

nhl_players

Retrieve metadata for players based on names or ids
nhl_schedule

Retrieve metadata on NHL schedule from the API
nhl_url_add_params

Add parameters to URLs
nhl_md_game_statuses

Get game status metadata
nhl_seasons

Retrieve metadata on NHL seasons from the API
nhl_get_data_worker

Get data from the API for 1 URL
nhl_url_add_suffixes

Add suffixes to URLs
nhl_md_game_types

Get game type metadata
nhl_md_stat_types

Get stat types metadata
nhl_md_tournament_types

Get tournament types metadata
nhl_teams_rosters

Get rosters for teams
nhl_teams_shedule_next

Get details for the teams' upcoming game
nhl_url_divisions

Create an NHL API URL for divisions
nhl_url_tournaments

Create an NHL API URL for tournaments
nhl_plot_rink

Plot an NHL rink
nhl_url_draft_prospects

Create an NHL API URL for draft prospects
nhl_players_allseasons

Retrieve all seasons statistics for players
nhl_url_venues

Create an NHL API URL for venues
nhl_players_seasons

Retrieve selected seasons statistics for players
nhl_url_awards

Create an NHL API URL for awards
nhl_url_conferences

Create an NHL API URL for conferences
nhl_make_seasons

Make a vector of seasons consumable by the API
nhl_md_play_types

Get play types metadata
util_attributes_to_cols

Add attributes as data frame columns
nhl_venues

Retrieve metadata on NHL venues from the API
util_map_player_id

Retrieve a player id from the name
util_inherit_attributes

Inherit attributes from another object
nhl_standings

Retrieve metadata on NHL standings from the API
nhl_teams

Retrieve metadata on NHL teams from the API
nhl_md_standings_types

Get standings types metadata
nhl_url_players_stats

Create an NHL API stats URL for players
nhl_url_players_seasons

Create an NHL API URL for players' seasons statistics
nhl_md_event_types

Get event types metadata
nhl_url_drafts

Create an NHL API URL for drafts
nhl_url_games

Create an NHL API URL for games
nhl_teams_shedule_previous

Get details for the teams' previous game
nhl_teams_stats

Get team statistics per seasons
nhl_tournaments

Retrieve data on tournaments from the API
util_md5sum_str

Get MD5 hash for a character vector
util_map_player_ids

Retrieve a player ids from their names
util_prepare_player_ids

Prepare player ids based on player names
nhl_url_players

Create an NHL API URL for players
nhl_url_players_allseasons

Create an NHL API URL for all players' seasons statistics
util_process_minsonice

Convert time columns from "mm:ss" to numeric minutes
util_process_copyright

Move copyright information to attribute
nhl_url

Create an NHL API URL
nhl_url_standings

Create an NHL API URL for standings
util_rbindlist

Safely rbind multiple data.frames
nhl_url_schedule

Create an NHL API URL for schedules
nhl_url_teams

Create an NHL API URL for teams
util_convert_minsonice

Convert "mm:ss" character to numeric minutes
nhl_url_seasons

Create an NHL API URL for seasons
util_generate_sysdata

Generate the sysdata.rda file
util_report_get_data_errors

Report errors encountered during nhl_get_data
nhl_from_json

Get URL using fromJSON
nhl_drafts

Retrieve metadata on NHL drafts from the API
nhl_draft_prospects

Retrieve metadata on NHL draft prospects from the API
nhl_conferences

Retrieve metadata on NHL conferences from the API
nhl_games

Retrieve metadata on NHL games from the API
nhl_get_data

Get data from the API for one or more URLs
nhl_divisions

Retrieve metadata on NHL divisions from the API
make_log

Create a log message
nhl_awards

Retrieve metadata on NHL awards from the API