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_nametypes
idnumeric
sequence_numbercharacter
type_idinteger
type_textcharacter
textcharacter
away_scoreinteger
home_scoreinteger
period_numberinteger
period_display_valuecharacter
clock_display_valuecharacter
scoring_playlogical
score_valueinteger
team_idinteger
athlete_id_1integer
athlete_id_2integer
athlete_id_3integer
wallclockcharacter
shooting_playlogical
coordinate_x_rawnumeric
coordinate_y_rawnumeric
seasoninteger
season_typeinteger
away_team_idinteger
away_team_namecharacter
away_team_mascotcharacter
away_team_abbrevcharacter
away_team_name_altcharacter
home_team_idinteger
home_team_namecharacter
home_team_mascotcharacter
home_team_abbrevcharacter
home_team_name_altcharacter
home_team_spreadnumeric
game_spreadnumeric
home_favoritelogical
game_spread_availablelogical
game_idinteger
qtrinteger
timecharacter
clock_minutesinteger
clock_secondsnumeric
halfcharacter
game_halfcharacter
lead_qtrinteger
lead_game_halfcharacter
start_quarter_seconds_remaininginteger
start_half_seconds_remaininginteger
start_game_seconds_remaininginteger
game_play_numberinteger
end_quarter_seconds_remaininginteger
end_half_seconds_remaininginteger
end_game_seconds_remaininginteger
periodinteger
lag_qtrinteger
lag_game_halfcharacter
coordinate_xnumeric
coordinate_ynumeric
game_dateDate
game_date_timePOSIXct
type_abbreviationcharacter

Examples

# \donttest{
  load_nba_pbp(seasons = most_recent_nba_season())
#> ── ESPN NBA Play-by-Play from hoopR data repository ───────────── hoopR 2.1.0 ──
#>  Data updated: 2023-11-28 12:28:41 UTC
#> # A tibble: 118,869 × 62
#>    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  Dani…          0
#>  2                2   4.02e 9               7     126 Layup Dr… Jade…          0
#>  3                3   4.02e 9               8     156 Offensiv… Jade…          0
#>  4                4   4.02e 9               9      94 Tip Shot  Jade…          0
#>  5                5   4.02e10              10     110 Driving … Jale…          0
#>  6                6   4.02e10              12     155 Defensiv… Cade…          0
#>  7                7   4.02e10              13      95 Layup Sh… Cade…          0
#>  8                8   4.02e10              14     132 Step Bac… Kyle…          0
#>  9                9   4.02e10              15     155 Defensiv… Jale…          0
#> 10               10   4.02e10              16     127 Layup Ru… Ausa…          0
#> # ℹ 118,859 more rows
#> # ℹ 55 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>, game_id <int>,
#> #   season <int>, season_type <int>, home_team_id <int>, …
# }