Learn R Programming

nhlapi (version 0.1.4)

nhl_games: Retrieve metadata on NHL games from the API

Description

Retrieve metadata on NHL games from the API

Usage

nhl_games(gameIds, element)

nhl_games_content(gameIds)

nhl_games_feed(gameIds)

nhl_games_boxscore(gameIds)

nhl_games_linescore(gameIds)

Arguments

gameIds

numeric(), vector of one or more game ids. The game id is a 10 digit number where the

  • first 4 digits identify the season of the game, for instance 2017 for the 2017-2018 season.

  • next 2 digits give the type of game, where

    • 01 - preseason,

    • 02 - regular season,

    • 03 - playoffs,

    • 04 - all-star.

  • final 4 digits identify the specific game number

    • for regular season and preseason games, this ranges from 0001 to the number of games played. That is 1271 for seasons with 31 teams and 1230 for seasons with 30 teams.

    • for playoff games, the

      • second digit gives the round of the playoffs

      • third digit specifies the match-up

      • fourth digit specifies the game (out of 7)

element

character() vector of one or more valid elements. Currently the valid elements seem to be:

  • "linescore"

  • "boxscore"

  • "content"

  • "feed/live"

Value

list, with information on games, one element per game and element combination.

Functions

  • nhl_games_content: Complex endpoint returning multiple types of media relating to the game including videos of shots, goals and saves.

  • nhl_games_feed: returns all data about a specified game id including play data with on-ice coordinates and post-game details like first, second and third stars and details about shootouts. Note that the data returned is sizable, often over 30 000 lines.

  • nhl_games_boxscore: Returns far less detail than nhl_games_feed() and may be more suitable for analyzing post-game statistics including goals, shots, penalty minutes, blocked, takeaways, etc.

  • nhl_games_linescore: Returns even fewer details than nhl_games_boxscore(). Has goals, shots on goal, power-play and goalie pulled status, number of skaters and shootout information if applicable.

Examples

Run this code
# NOT RUN {
  # Get content for one game
  nhl_games(2017010001, "content")

  # Get both box score and content for 2 games
  nhl_games(c(2017010001, 2017010002), c("content", "boxscore"))

  # Get content for a game
  nhl_games_content(2017010001)

  # Get the game feed for a game
  nhl_games_feed(2017010001)

  # Get the box score for a game
  nhl_games_boxscore(2017010001)

  # Get the line score for a game
  nhl_games_linescore(2017010001)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab