Skip to contents

Helper that loads multiple seasons of pre-scraped NHL play-by-play data (full version, including line changes and shifts) from the sportsdataverse-data releases either into memory or writes it into a database.

Usage

load_nhl_pbp(
  seasons = most_recent_nhl_season(),
  ...,
  dbConnection = NULL,
  tablename = NULL
)

Arguments

seasons

A vector of 4-digit years (the end year of the NHL season; e.g., 2026 for the 2025-26 season). Min: 2011.

...

Additional arguments passed to an underlying function that writes the season data into a database (used by update_nhl_db()).

dbConnection

A DBIConnection object, as returned by DBI::dbConnect()

tablename

The name of the play by play data table within the database

Value

A data frame (fastRhockey_data) with the following columns:

col_nametypesdescription
event_typecharacterStandardized event type code.
eventcharacterEvent description label.
secondary_typecharacterSecondary event type (e.g. shot type).
event_team_abbrcharacterAbbreviation of the team credited with the event.
event_team_typecharacterWhether the event team is home or away.
descriptioncharacterFull text description of the event.
periodintegerPeriod number.
period_typecharacterPeriod type (REGULAR/OVERTIME/SHOOTOUT).
period_timecharacterElapsed time in the period (MM:SS).
period_secondsintegerElapsed seconds in the period.
period_seconds_remainingintegerSeconds remaining in the period.
period_time_remainingcharacterTime remaining in the period (MM:SS).
game_secondsintegerElapsed seconds in the game.
game_seconds_remainingintegerSeconds remaining in regulation.
home_scoreintegerHome team score after the event.
away_scoreintegerAway team score after the event.
event_player_1_namecharacterName of the primary event player.
event_player_1_typecharacterRole of the primary event player.
event_player_1_idintegerPlayer id of the primary event player.
event_player_2_namecharacterName of the secondary event player.
event_player_2_typecharacterRole of the secondary event player.
event_player_2_idintegerPlayer id of the secondary event player.
event_player_3_namecharacterName of the tertiary event player.
event_player_3_typecharacterRole of the tertiary event player.
event_player_3_idintegerPlayer id of the tertiary event player.
event_goalie_namecharacterName of the goalie on the event.
event_goalie_idintegerPlayer id of the goalie on the event.
penalty_severitycharacterSeverity of the penalty.
penalty_minutesintegerPenalty minutes assessed.
strength_statecharacterStrength state (e.g. 5v5, 5v4).
strength_codecharacterCoded strength state.
strengthcharacterStrength description.
empty_netlogicalWhether the net was empty.
extra_attackerlogicalWhether an extra attacker was on the ice.
xintegerRaw x-coordinate of the event.
yintegerRaw y-coordinate of the event.
x_fixedintegerSide-adjusted x-coordinate.
y_fixedintegerSide-adjusted y-coordinate.
shot_distancenumericDistance of the shot from the net.
shot_anglenumericAngle of the shot relative to the net.
home_skatersintegerNumber of home skaters on the ice.
away_skatersintegerNumber of away skaters on the ice.
home_on_1characterName of home skater 1 on the ice.
home_on_2characterName of home skater 2 on the ice.
home_on_3characterName of home skater 3 on the ice.
home_on_4characterName of home skater 4 on the ice.
home_on_5characterName of home skater 5 on the ice.
home_on_6characterName of home skater 6 on the ice.
home_on_7characterName of home skater 7 on the ice.
away_on_1characterName of away skater 1 on the ice.
away_on_2characterName of away skater 2 on the ice.
away_on_3characterName of away skater 3 on the ice.
away_on_4characterName of away skater 4 on the ice.
away_on_5characterName of away skater 5 on the ice.
away_on_6characterName of away skater 6 on the ice.
away_on_7characterName of away skater 7 on the ice.
home_goaliecharacterName of the home goalie on the ice.
away_goaliecharacterName of the away goalie on the ice.
num_onintegerNumber of players coming on (line change).
players_oncharacterNames of players coming on.
num_offintegerNumber of players going off (line change).
players_offcharacterNames of players going off.
game_idintegerUnique game identifier.
seasonintegerSeason (concluding year, YYYY).
season_typecharacterSeason type (regular/playoffs).
home_abbrcharacterHome team abbreviation.
away_abbrcharacterAway team abbreviation.
event_idxintegerSequential event index within the game.
event_idintegerNHL event identifier.
away_goalie_inintegerWhether the away goalie is in net (1/0).
home_goalie_inintegerWhether the home goalie is in net (1/0).
reasoncharacterReason for the event (e.g. stoppage reason).
secondaryReasoncharacterSecondary reason for the event.
ids_oncharacterPlayer ids coming on.
ids_offcharacterPlayer ids going off.
home_on_1_idintegerPlayer id of home skater 1 on the ice.
away_on_1_idintegerPlayer id of away skater 1 on the ice.
home_on_2_idintegerPlayer id of home skater 2 on the ice.
away_on_2_idintegerPlayer id of away skater 2 on the ice.
home_on_3_idintegerPlayer id of home skater 3 on the ice.
away_on_3_idintegerPlayer id of away skater 3 on the ice.
home_on_4_idintegerPlayer id of home skater 4 on the ice.
away_on_4_idintegerPlayer id of away skater 4 on the ice.
home_on_5_idintegerPlayer id of home skater 5 on the ice.
away_on_5_idintegerPlayer id of away skater 5 on the ice.
home_on_6_idintegerPlayer id of home skater 6 on the ice.
away_on_6_idintegerPlayer id of away skater 6 on the ice.
home_on_7_idintegerPlayer id of home skater 7 on the ice.
away_on_7_idintegerPlayer id of away skater 7 on the ice.
home_goalie_idintegerPlayer id of the home goalie on the ice.
away_goalie_idintegerPlayer id of the away goalie on the ice.
xgnumericExpected goals value for the shot event.

Examples

# \donttest{
  try(load_nhl_pbp(2022))
#> ── NHL Play-by-Play (full, with shifts) from fastRhockey data repository ───────
#>  Data updated: 2026-04-08 05:53:06 UTC
#> # A tibble: 975,777 × 92
#>    event_type   event secondary_type event_team_abbr event_team_type description
#>    <chr>        <chr> <chr>          <chr>           <chr>           <chr>      
#>  1 CHANGE       Chan… NA             NA              NA              ON: Jeff C…
#>  2 CHANGE       Chan… NA             NA              NA              ON: Ryan M…
#>  3 FACEOFF      Face… NA             PIT             away            Jeff Carte…
#>  4 PERIOD_START Peri… NA             NA              NA              Start of P…
#>  5 HIT          Hit   NA             TBL             home            Ondrej Pal…
#>  6 CHANGE       Chan… NA             NA              NA              ON: Marcus…
#>  7 CHANGE       Chan… NA             NA              NA              ON: Alex K…
#>  8 CHANGE       Chan… NA             NA              NA              ON: Jason …
#>  9 STOP         Stop… NA             NA              NA              Stoppage i…
#> 10 FACEOFF      Face… NA             TBL             home            Anthony Ci…
#> # ℹ 975,767 more rows
#> # ℹ 86 more variables: period <int>, period_type <chr>, period_time <chr>,
#> #   period_seconds <int>, period_seconds_remaining <int>,
#> #   period_time_remaining <chr>, game_seconds <int>,
#> #   game_seconds_remaining <int>, home_score <int>, away_score <int>,
#> #   event_player_1_name <chr>, event_player_1_type <chr>,
#> #   event_player_1_id <int>, event_player_2_name <chr>, …
# }