Skip to contents

Helper that loads multiple seasons of pre-scraped PWHL play-by-play data from the sportsdataverse-data releases either into memory or writes it into a database.

Usage

load_pwhl_pbp(
  seasons = most_recent_pwhl_season(),
  ...,
  dbConnection = NULL,
  tablename = NULL
)

Arguments

seasons

A vector of 4-digit years associated with given PWHL seasons. (Min: 2024)

...

Additional arguments passed to an underlying function that writes the season data into a database (used by update_pwhl_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
game_idintegerUnique game identifier.
eventcharacterPlay-by-play event description.
team_idintegerTeam identifier for the event.
period_of_gamecharacterPeriod in which the event occurred.
time_of_periodcharacterGame clock time within the period.
player_idintegerPrimary player identifier.
player_name_firstcharacterPrimary player first name.
player_name_lastcharacterPrimary player last name.
player_positioncharacterPrimary player position.
player_two_idintegerSecond player identifier.
player_two_name_firstcharacterSecond player first name.
player_two_name_lastcharacterSecond player last name.
player_two_positioncharacterSecond player position.
x_coordnumericEvent x-coordinate on the ice.
y_coordnumericEvent y-coordinate on the ice.
home_winintegerFlag for whether the home team won.
player_team_idintegerTeam identifier of the primary player.
event_typecharacterCategorized event type.
shot_qualitycharacterShot quality descriptor.
goallogicalFlag for whether the event was a goal.
goalie_idintegerGoalie identifier on the play.
goalie_firstcharacterGoalie first name.
goalie_lastcharacterGoalie last name.
player_three_idintegerThird player identifier.
player_three_name_firstcharacterThird player first name.
player_three_name_lastcharacterThird player last name.
player_three_positioncharacterThird player position.
empty_netcharacterEmpty-net flag.
game_winnercharacterGame-winning-goal flag.
penalty_shotcharacterPenalty-shot flag.
insurancecharacterInsurance-goal flag.
power_playintegerPower-play flag.
short_handedcharacterShort-handed flag.
plus_player_one_idintegerOn-ice plus player one identifier.
plus_player_one_firstcharacterOn-ice plus player one first name.
plus_player_one_lastcharacterOn-ice plus player one last name.
plus_player_one_positioncharacterOn-ice plus player one position.
plus_player_two_idintegerOn-ice plus player two identifier.
plus_player_two_firstcharacterOn-ice plus player two first name.
plus_player_two_lastcharacterOn-ice plus player two last name.
plus_player_two_positioncharacterOn-ice plus player two position.
plus_player_three_idintegerOn-ice plus player three identifier.
plus_player_three_firstcharacterOn-ice plus player three first name.
plus_player_three_lastcharacterOn-ice plus player three last name.
plus_player_three_positioncharacterOn-ice plus player three position.
plus_player_four_idintegerOn-ice plus player four identifier.
plus_player_four_firstcharacterOn-ice plus player four first name.
plus_player_four_lastcharacterOn-ice plus player four last name.
plus_player_four_positioncharacterOn-ice plus player four position.
plus_player_five_idintegerOn-ice plus player five identifier.
plus_player_five_firstcharacterOn-ice plus player five first name.
plus_player_five_lastcharacterOn-ice plus player five last name.
plus_player_five_positioncharacterOn-ice plus player five position.
minus_player_one_idintegerOn-ice minus player one identifier.
minus_player_one_firstcharacterOn-ice minus player one first name.
minus_player_one_lastcharacterOn-ice minus player one last name.
minus_player_one_positioncharacterOn-ice minus player one position.
minus_player_two_idintegerOn-ice minus player two identifier.
minus_player_two_firstcharacterOn-ice minus player two first name.
minus_player_two_lastcharacterOn-ice minus player two last name.
minus_player_two_positioncharacterOn-ice minus player two position.
minus_player_three_idintegerOn-ice minus player three identifier.
minus_player_three_firstcharacterOn-ice minus player three first name.
minus_player_three_lastcharacterOn-ice minus player three last name.
minus_player_three_positioncharacterOn-ice minus player three position.
minus_player_four_idintegerOn-ice minus player four identifier.
minus_player_four_firstcharacterOn-ice minus player four first name.
minus_player_four_lastcharacterOn-ice minus player four last name.
minus_player_four_positioncharacterOn-ice minus player four position.
minus_player_five_idintegerOn-ice minus player five identifier.
minus_player_five_firstcharacterOn-ice minus player five first name.
minus_player_five_lastcharacterOn-ice minus player five last name.
minus_player_five_positioncharacterOn-ice minus player five position.
penalty_lengthcharacterPenalty length in minutes.
game_datecharacterGame date.
game_seasonintegerSeason (concluding year, YYYY).
game_season_idcharacterHockeyTech season identifier.
home_team_idintegerHome team identifier.
home_teamcharacterHome team name.
away_team_idintegerAway team identifier.
away_teamcharacterAway team name.
x_coord_originalintegerOriginal raw x-coordinate.
y_coord_originalintegerOriginal raw y-coordinate.
x_coord_neutralintegerNeutral-orientation x-coordinate.
y_coord_neutralintegerNeutral-orientation y-coordinate.
x_coord_fixednumericFixed-orientation x-coordinate.
y_coord_fixednumericFixed-orientation y-coordinate.
x_coord_rightnumericRight-orientation x-coordinate.
y_coord_rightnumericRight-orientation y-coordinate.
x_coord_verticalnumericVertical-orientation x-coordinate.
y_coord_verticalnumericVertical-orientation y-coordinate.
minute_startintegerMinute the event started.
second_startintegerSecond the event started.
clockcharacterGame clock string.
sec_from_startintegerSeconds elapsed from the start of the game.

Examples

# \donttest{
  try(load_pwhl_pbp(2024))
#> ─────────────────────────────────────────────────────────── fastRhockey 1.0.0 ──
#> # A tibble: 10,456 × 95
#>    game_id event   team_id period_of_game time_of_period player_id
#>      <int> <chr>     <int> <chr>          <chr>              <int>
#>  1       2 faceoff      NA 1              0:00                  76
#>  2       2 shot          4 1              1:29                  44
#>  3       2 shot          4 1              3:30                  36
#>  4       2 shot          4 1              3:36                  46
#>  5       2 faceoff      NA 1              4:30                  73
#>  6       2 shot          4 1              4:57                  86
#>  7       2 faceoff      NA 1              5:18                  73
#>  8       2 shot          4 1              6:42                  38
#>  9       2 shot          6 1              7:05                 128
#> 10       2 shot          6 1              9:12                 126
#> # ℹ 10,446 more rows
#> # ℹ 89 more variables: player_name_first <chr>, player_name_last <chr>,
#> #   player_position <chr>, player_two_id <int>, player_two_name_first <chr>,
#> #   player_two_name_last <chr>, player_two_position <chr>, x_coord <dbl>,
#> #   y_coord <dbl>, home_win <int>, player_team_id <int>, event_type <chr>,
#> #   shot_quality <chr>, goal <lgl>, goalie_id <int>, goalie_first <chr>,
#> #   goalie_last <chr>, player_three_id <int>, player_three_name_first <chr>, …
# }