Scrapes play-by-play data for a specified game ID.

scrape_game(game_id)

Arguments

game_id

Game ID to scrape

Value

A tibble containing event-based play-by-play data for an individual NHL game. The resulting data will have columns for:

xg

Numeric expected goal value for unblocked shot events

event

String defining the event

event_type

String with alternate event definition; in all caps

secondary_type

String defining secondary event type

event_team

String defining the primary team involved in the event

event_team_type

String indicator of event team type: home or away

description

String detailed description of event

period

Integer value of the game period

period_seconds

Numeric value of the seconds into the period of the event

period_seconds_remaining

Numeric value of the seconds remaining in the period

game_seconds

Numeric value of the seconds into the game of the event

game_seconds_remaining

Numeric value of the seconds remaining in the game; negative for overtime periods

home_score

Integer value of the home team score after the event

away_score

Integer value of the away team score after the event

event_player_1_name

String name of the primary event player

event_player_1_type

String indicator for the role of event_player_1

event_player_2_name

String name of the secondary event player

event_player_2_type

String indicator for the role of event_player_2

event_player_3_name

String name of the tertiary event player

event_player_3_type

String indicator for the role of event_player_3

event_goalie_name

String name of the goalie involved in the event

strength_code

String indicator for game strength: EV, SH, or PP

strength

String name for game strength: Even, Shorthanded, or Power Play

strength_state

String name for detailed game strength in the form of '(event team skaters)v(opponent skaters)'

penalty_minutes

Integer value of the penalty minutes on penalty events

penalty_severity

String name for penalty severity: Minor or Major

num_on

Integer value of the number of skaters substituted on during a shift change event

players_on

String of player names substituted on during a shift change event

num_off

Integer value of the number of skaters substituted off during a shift change event

players_off

String of player names substituted off during a shift change event

extra_attacker

Logical indicator of whether or not the event team had their goalie pulled

x

Numeric x-coordinate of event in feet, with origin at center ice

y

Numeric y-coordinate of event in feet, with origin at center ice

x_fixed

Numeric transformed x-coordinate of event in feet, where the home team always shoots to the right, away team to the left

y_fixed

Numeric transformed y-coordinate of event in feet, where the home team always shoots to the right, away team to the left

shot_distance

Numeric distance (in feet) to center of net for unblocked shot events

shot_angle

Numeric angle (in degrees) to center of net for unlocked shot events

home_skaters

Numeric value for number of skaters on the ice for the home team, excluding the goalie

away_skaters

Numeric value for number of skaters on the ice for the away team, excluding the goalie

home_on_1

String name of home team player on ice

home_on_2

String name of home team player on ice

home_on_3

String name of home team player on ice

home_on_4

String name of home team player on ice

home_on_5

String name of home team player on ice

home_on_6

String name of home team player on ice

home_on_7

String name of home team player on ice

away_on_1

String name of away team player on ice

away_on_2

String name of away team player on ice

away_on_3

String name of away team player on ice

away_on_4

String name of away team player on ice

away_on_5

String name of away team player on ice

away_on_6

String name of away team player on ice

away_on_7

String name of away team player on ice

home_goalie

String name of home goalie on ice

away_goalie

String name of away goalie on ice

game_id

Integer value of assigned game ID

event_idx

Numeric index for event

event_id

Numeric id for event -- more specified than event_idx

event_player_1_id

Integer value of the player ID for the primary event player

event_player_1_link

String value of the NHL.com player link for the primary event player

event_player_1_season_total

Integer value for the total events for the primary event player this season

event_player_2_id

Integer value of the player ID for the secondary event player

event_player_2_link

String value of the NHL.com player link for the secondary event player

event_player_2_season_total

Integer value for the total events for the secondary event player this season

event_player_3_id

Integer value of the player ID for the tertiary event player

event_player_3_link

String value of the NHL.com player link for the tertiary event player

event_player_3_season_total

Integer value for the total events for the tertiary event player this season

event_goalie_id

Integer value of the player ID for the event goalie

event_goalie_link

String value of the NHL.com player link for the event goalie

event_goalie_type

String indicator for the role of the event_goalie

game_winning_goal

Logical indicator of whether or not the goal scored was the game-winning goal

empty_net

Logical indicator of whether or not the goal scored was on an empty net

period_type

String name of period type: REGULAR, OVERTIME, or SHOOTOUT

ordinal_num

String name of the ordinal period: 1st, 2nd, 3rd, 4th...

period_time

String value of the time into the period of the event

period_time_remaining

String value of the time remaining in the period

date_time

String value of the real-world timestamp of the event

event_team_id

Integer value of the NHL ID of event_team

event_team_link

String value of the NHL.com team link for the event_team

event_team_abbr

String value of the 3-letter NHL abbreviation for the event_team

home_final

Integer value of the final score for the home team

away_final

Integer value of the final score for the away team

season

String value of the official NHL season

season_type

String indicator of season type: R, or P

game_date

Date of game

game_start

Date time of start of game in US/Eastern time zone

game_end

Date time of end of game in US/Eastern time zone

game_length

Period value of length of game, in hours:minutes

game_state

String indicator of state of game

detailed_state

String indicator of detailed game state

venue_id

Integer value of the NHL ID for the venue

venue_name

String name of the game venue

venue_link

String value of the NHL.com link for the venue

home_name

String name of the home team

home_abbreviation

String value of the 3-letter NHL abbreviation of the home team

home_division_name

String value of the name of the NHL division of the home team

home_conference_name

String value of the name of the NHL conference of the home team

home_id

Integer value of the NHL ID of the home team

away_name

String name of the away team

away_abbreviation

String value of the 3-letter NHL abbreviation of the away team

away_division_name

String value of the name of the NHL division of the away team

away_conference_name

String value of the name of the NHL conference of the away team

away_id

Integer value of the NHL ID of the away team

Examples

if (FALSE) {
pbp <- scrape_game(2020020420)
}