If you were to try and analyze statistics for your favorite hockey team, or try to predict an outcome of the next match you’d probably browse the internet in search of convenient tools to get the data you want from the NHL website. While there are a bunch of NHL API packages available in python, there is limited availability of many R packages. Therefore, the rpuck library is designed to allow users the ability to conveniently get both relevant and historical statistics from the publicly available but as of yet undocumented NHL.com API. As of now the package has limited functionality, and is considered a work-in-progress. We will add in additional functionality in the coming weeks which can easily be extended based on feedback we recieve.
You can install the released version of rpuck from CRAN with:
install.packages("rpuck")
And the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("UBC-MDS/rpuck")
draft_pick(pick_number=NULL, round_number=NULL, year=NULL)
:
draft_pick( )
function makes an API call to the drafts summary on the NHL.com API. The function returns information about draft picks for the specified arguments and stores them in a data frame.attendance(regular=True, playoffs=True, start_season=NULL, end_season=NULL)
:
team_stats(start_season=NULL, end_season=NULL)
:
team_stats( )
function makes an API call to the team summary endpoint on the NHL.com API. The function returns team seasonal stats for given seasons sorted by total team points.player_stats(start_date=NULL, end_date=NULL)
:
player_stats( )
function makes an API call to the player summary endpoint on the NHL.com API. The function returns the top 100 player stats for a given date range as sorted by total points.The package can extract and visualize data from NHL statistics in convenient format. Below is an example of how one can use rpuck.
To load the package:
library(rpuck)
Get a chart showing the attendance over a specified time period:
attendance <- attendance(regular=TRUE, playoffs=TRUE, start_season= 2001, end_season=2018)
Result of draft by pick number, draft number and year in summary report:
pick <- draft_pick(pick_number = 1, round_number = 2, year = 2019)
Query the top 100 player’s stats from the player’s summary report:
player_s <- player_stats(start_date = "2019-10-02", end_date = "2020-02-28")
head(player_s)
Stats for teams specified by start year or start year and end year:
attendance <- team_stats(start_season = "19801981", end_season = "19891990")
head(attendance)
We have included a variety of tests for each function in the tests\testthat
directory. The tests check that the functions error gracefully and that proper function calls return the correct data/objects.