Skip to contents

helper that loads multiple seasons from the data repo either into memory or writes it into a db using some forwarded arguments in the dots

Usage

load_nba_pbp(
  seasons = most_recent_nba_season(),
  ...,
  dbConnection = NULL,
  tablename = NULL
)

Arguments

seasons

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

...

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

dbConnection

A DBIConnection object, as returned by

tablename

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

Value

Returns a tibble

col_nametypesdescription
idnumericId.
sequence_numbercharacterSequence number representing a shot-possession (V3 PBP).
type_idintegerType identifier (numeric).
type_textcharacterDisplay text for the type field.
textcharacterText description of the play / record.
away_scoreintegerAway team score at the time of the play.
home_scoreintegerHome team score at the time of the play.
period_numberintegerNumeric period (1-4 for quarters; 5+ for OT).
period_display_valuecharacterPeriod display label (e.g. '1st Quarter', 'OT').
clock_display_valuecharacterGame clock display string (e.g. '8:32').
scoring_playlogicalTRUE if the play resulted in points scored.
score_valueintegerPoint value of the play (2 / 3 / 1).
team_idintegerUnique team identifier.
athlete_id_1integerPrimary athlete identifier (e.g. shooter).
athlete_id_2integerSecondary athlete identifier (e.g. assister / fouler).
athlete_id_3integerAthlete id 3.
wallclockcharacterWallclock.
shooting_playlogicalTRUE if the play was a shooting attempt.
coordinate_x_rawnumericX coordinate as returned by the API before any adjustment.
coordinate_y_rawnumericY coordinate as returned by the API before any adjustment.
seasonintegerSeason identifier (4-digit year or 'YYYY-YY' string).
season_typeintegerSeason type (1=pre-season, 2=regular season, 3=postseason, 4=off-season for ESPN; or string label for WNBA Stats).
away_team_idintegerUnique identifier for the away team.
away_team_namecharacterAway team name.
away_team_mascotcharacterAway team mascot.
away_team_abbrevcharacterAway team three-letter abbreviation.
away_team_name_altcharacterAlternate away team name.
home_team_idintegerUnique identifier for the home team.
home_team_namecharacterHome team name.
home_team_mascotcharacterHome team mascot.
home_team_abbrevcharacterHome team three-letter abbreviation.
home_team_name_altcharacterAlternate home team name.
home_team_spreadnumericHome team's point spread.
game_spreadnumericGame spread (signed; positive = home favored).
home_favoritelogicalTRUE if the home team is the betting favorite.
game_spread_availablelogicalTRUE if a point spread was available.
game_idintegerUnique game identifier.
qtrintegerQuarter (1-4) or OT period (5+).
timecharacterTime / clock value.
clock_minutesintegerClock minutes split out for convenience.
clock_secondsnumericClock seconds split out for convenience.
halfcharacterHalf of the game (1 or 2).
game_halfcharacterHalf of the game (1 or 2).
lead_qtrintegerQuarter lead (the next-play's quarter).
lead_game_halfcharacterHalf lead (the next-play's half).
start_quarter_seconds_remainingintegerSeconds remaining in the period at the start of the play.
start_half_seconds_remainingintegerSeconds remaining in the half at the start of the play.
start_game_seconds_remainingintegerSeconds remaining in the game at the start of the play.
game_play_numberintegerSequential play number within the game.
end_quarter_seconds_remainingintegerSeconds remaining in the period at the end of the play.
end_half_seconds_remainingintegerSeconds remaining in the half at the end of the play.
end_game_seconds_remainingintegerSeconds remaining in the game at the end of the play.
periodintegerPeriod of the game (1-4 quarters; 5+ for OT).
lag_qtrintegerQuarter lag (the previous-play's quarter).
lag_game_halfcharacterHalf lag (the previous-play's half).
coordinate_xnumericX coordinate on the court (half-court layout).
coordinate_ynumericY coordinate on the court (half-court layout).
game_dateDateGame date (YYYY-MM-DD).
game_date_timePOSIXctGame start date/time (ISO 8601).
type_abbreviationcharacterType abbreviation.

Examples

# \donttest{
load_nba_pbp(seasons = most_recent_nba_season())
#> ── ESPN NBA Play-by-Play from hoopR data repository ───────────── hoopR 3.1.0 ──
#>  Data updated: 2026-05-29 19:12:53 UTC
#> # A tibble: 639,462 × 64
#>    game_play_number        id sequence_number type_id type_text text  away_score
#>               <int>     <dbl>           <int>   <int> <chr>     <chr>      <int>
#>  1                1   4.02e 9               4     615 Jumpball  Chet…          0
#>  2                2   4.02e 9               7      92 Jump Shot Juli…          0
#>  3                3   4.02e 9               9     130 Floating… Isai…          2
#>  4                4   4.02e10              11      92 Jump Shot Vict…          2
#>  5                5   4.02e10              13     128 Driving … Vict…          2
#>  6                6   4.02e10              14     156 Offensiv… Isai…          2
#>  7                7   4.02e10              19      92 Jump Shot Chet…          2
#>  8                8   4.02e10              20     155 Defensiv… Spur…          2
#>  9                9   4.02e10              15      92 Jump Shot Vict…          2
#> 10               10   4.02e10              17      16 Full Tim… Thun…          2
#> # ℹ 639,452 more rows
#> # ℹ 57 more variables: home_score <int>, period_number <int>,
#> #   period_display_value <chr>, clock_display_value <chr>, scoring_play <lgl>,
#> #   score_value <int>, team_id <int>, athlete_id_1 <int>, athlete_id_2 <int>,
#> #   athlete_id_3 <int>, wallclock <chr>, shooting_play <lgl>,
#> #   coordinate_x_raw <dbl>, coordinate_y_raw <dbl>, points_attempted <int>,
#> #   short_description <chr>, game_id <int>, season <int>, season_type <int>, …
# }