Skip to contents

build_nflfastR_pbp is a convenient wrapper around 6 nflfastR functions:

Please see either the documentation of each function or the nflfastR Field Descriptions website to learn about the output.

Usage

build_nflfastR_pbp(
  game_ids,
  dir = getOption("nflfastR.raw_directory", default = NULL),
  ...,
  decode = TRUE,
  rules = TRUE
)

Arguments

game_ids

Vector of character ids or a data frame including the variable game_id (see details for further information).

dir

Path to local directory (defaults to option "nflfastR.raw_directory") where nflfastR searches for raw game play-by-play data. See save_raw_pbp() for additional information.

...

Additional arguments passed to the scraping functions (for internal use)

decode

If TRUE, the function decode_player_ids() will be executed.

rules

If FALSE, printing of the header and footer in the console output will be suppressed.

Value

An nflfastR play-by-play data frame like it can be loaded from https://github.com/nflverse/nflverse-data.

Details

To load valid game_ids please use the package function fast_scraper_schedules().

See also

For information on parallel processing and progress updates please see nflfastR.

Examples

# \donttest{
# Build nflfastR pbp for the 2018 and 2019 Super Bowls
try({# to avoid CRAN test problems
build_nflfastR_pbp(c("2018_21_NE_LA", "2019_21_SF_KC"))
})
#> ── Build nflfastR Play-by-Play Data ───────────── nflfastR version 4.6.1.9008 ──
#> • 19:13:25 | Start download of 2 games...
#>  It is recommended to use parallel processing when trying to load multiple games.Please consider running `future::plan("multisession")`! Will go on sequentially...
#>  19:13:27 | Download finished. Adding variables...
#>  19:13:27 | added game variables
#>  19:13:27 | added nflscrapR variables
#> [19:13:28] WARNING: src/learner.cc:553: 
#>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
#>   older XGBoost, please export the model by calling `Booster.save_model` from that version
#>   first, then load it back in current version. See:
#> 
#>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
#> 
#>   for more details about differences between saving model and serializing.
#> 
#>  19:13:28 | added ep variables
#>  19:13:28 | added air_yac_ep variables
#> [19:13:28] WARNING: src/learner.cc:553: 
#>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
#>   older XGBoost, please export the model by calling `Booster.save_model` from that version
#>   first, then load it back in current version. See:
#> 
#>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
#> 
#>   for more details about differences between saving model and serializing.
#> 
#> [19:13:28] WARNING: src/learner.cc:553: 
#>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
#>   older XGBoost, please export the model by calling `Booster.save_model` from that version
#>   first, then load it back in current version. See:
#> 
#>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
#> 
#>   for more details about differences between saving model and serializing.
#> 
#>  19:13:28 | added wp variables
#>  19:13:28 | added air_yac_wp variables
#> [19:13:29] WARNING: src/learner.cc:553: 
#>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
#>   older XGBoost, please export the model by calling `Booster.save_model` from that version
#>   first, then load it back in current version. See:
#> 
#>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
#> 
#>   for more details about differences between saving model and serializing.
#> 
#>  19:13:29 | added cp and cpoe
#>  19:13:29 | added fixed drive variables
#>  19:13:29 | added series variables
#> • 19:13:29 | Cleaning up play-by-play...
#>  19:13:29 | Cleaning completed
#>  19:13:29 | added qb_epa
#> • 19:13:29 | Computing xyac...
#> [19:13:30] WARNING: src/learner.cc:553: 
#>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
#>   older XGBoost, please export the model by calling `Booster.save_model` from that version
#>   first, then load it back in current version. See:
#> 
#>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
#> 
#>   for more details about differences between saving model and serializing.
#> 
#>  19:13:31 | added xyac variables
#> • 19:13:31 | Computing xpass...
#> [19:13:31] WARNING: src/learner.cc:553: 
#>   If you are loading a serialized model (like pickle in Python, RDS in R) generated by
#>   older XGBoost, please export the model by calling `Booster.save_model` from that version
#>   first, then load it back in current version. See:
#> 
#>     https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html
#> 
#>   for more details about differences between saving model and serializing.
#> 
#>  19:13:31 | added xpass and pass_oe
#> • 19:13:31 | Decode player ids...
#>  19:13:32 | Decoding of player ids completed
#> ── DONE ────────────────────────────────────────────────────────────────────────
#> ── nflverse play by play ───────────────────────────────────────────────────────
#>  Data updated: 2024-03-28 19:13:32 UTC
#> # A tibble: 349 × 372
#>    play_id game_id     old_game_id home_team away_team season_type  week posteam
#>      <dbl> <chr>       <chr>       <chr>     <chr>     <chr>       <int> <chr>  
#>  1       1 2018_21_NE… 2019020300  LA        NE        POST           21 NA     
#>  2      38 2018_21_NE… 2019020300  LA        NE        POST           21 NE     
#>  3      67 2018_21_NE… 2019020300  LA        NE        POST           21 NE     
#>  4      89 2018_21_NE… 2019020300  LA        NE        POST           21 NE     
#>  5     111 2018_21_NE… 2019020300  LA        NE        POST           21 NE     
#>  6     133 2018_21_NE… 2019020300  LA        NE        POST           21 NE     
#>  7     155 2018_21_NE… 2019020300  LA        NE        POST           21 NE     
#>  8     182 2018_21_NE… 2019020300  LA        NE        POST           21 LA     
#>  9     204 2018_21_NE… 2019020300  LA        NE        POST           21 LA     
#> 10     226 2018_21_NE… 2019020300  LA        NE        POST           21 LA     
#> # ℹ 339 more rows
#> # ℹ 364 more variables: posteam_type <chr>, defteam <chr>, side_of_field <chr>,
#> #   yardline_100 <dbl>, game_date <chr>, quarter_seconds_remaining <dbl>,
#> #   half_seconds_remaining <dbl>, game_seconds_remaining <dbl>,
#> #   game_half <chr>, quarter_end <dbl>, drive <dbl>, sp <dbl>, qtr <dbl>,
#> #   down <dbl>, goal_to_go <int>, time <chr>, yrdln <chr>, ydstogo <dbl>,
#> #   ydsnet <dbl>, desc <chr>, play_type <chr>, yards_gained <dbl>, …

# It is also possible to directly use the
# output of `fast_scraper_schedules` as input
try({# to avoid CRAN test problems
library(dplyr, warn.conflicts = FALSE)
fast_scraper_schedules(2020) %>%
  slice_tail(n = 3) %>%
  build_nflfastR_pbp()
 })
#> ── Build nflfastR Play-by-Play Data ───────────── nflfastR version 4.6.1.9008 ──
#> • 19:13:32 | Start download of 3 games...
#>  It is recommended to use parallel processing when trying to load multiple games.Please consider running `future::plan("multisession")`! Will go on sequentially...
#>  19:13:34 | Download finished. Adding variables...
#>  19:13:34 | added game variables
#>  19:13:34 | added nflscrapR variables
#>  19:13:35 | added ep variables
#>  19:13:35 | added air_yac_ep variables
#>  19:13:35 | added wp variables
#>  19:13:35 | added air_yac_wp variables
#>  19:13:35 | added cp and cpoe
#>  19:13:35 | added fixed drive variables
#>  19:13:35 | added series variables
#> • 19:13:35 | Cleaning up play-by-play...
#>  19:13:35 | Cleaning completed
#>  19:13:36 | added qb_epa
#> • 19:13:36 | Computing xyac...
#>  19:13:37 | added xyac variables
#> • 19:13:37 | Computing xpass...
#>  19:13:37 | added xpass and pass_oe
#> • 19:13:37 | Decode player ids...
#>  19:13:37 | Decoding of player ids completed
#> ── DONE ────────────────────────────────────────────────────────────────────────
#> ── nflverse play by play ───────────────────────────────────────────────────────
#>  Data updated: 2024-03-28 19:13:37 UTC
#> # A tibble: 539 × 372
#>    play_id game_id     old_game_id home_team away_team season_type  week posteam
#>      <dbl> <chr>       <chr>       <chr>     <chr>     <chr>       <int> <chr>  
#>  1       1 2020_20_BU… 2021012401  KC        BUF       POST           20 NA     
#>  2      42 2020_20_BU… 2021012401  KC        BUF       POST           20 BUF    
#>  3      57 2020_20_BU… 2021012401  KC        BUF       POST           20 BUF    
#>  4      78 2020_20_BU… 2021012401  KC        BUF       POST           20 BUF    
#>  5     102 2020_20_BU… 2021012401  KC        BUF       POST           20 BUF    
#>  6     123 2020_20_BU… 2021012401  KC        BUF       POST           20 BUF    
#>  7     145 2020_20_BU… 2021012401  KC        BUF       POST           20 BUF    
#>  8     174 2020_20_BU… 2021012401  KC        BUF       POST           20 BUF    
#>  9     207 2020_20_BU… 2021012401  KC        BUF       POST           20 BUF    
#> 10     236 2020_20_BU… 2021012401  KC        BUF       POST           20 BUF    
#> # ℹ 529 more rows
#> # ℹ 364 more variables: posteam_type <chr>, defteam <chr>, side_of_field <chr>,
#> #   yardline_100 <dbl>, game_date <chr>, quarter_seconds_remaining <dbl>,
#> #   half_seconds_remaining <dbl>, game_seconds_remaining <dbl>,
#> #   game_half <chr>, quarter_end <dbl>, drive <dbl>, sp <dbl>, qtr <dbl>,
#> #   down <dbl>, goal_to_go <int>, time <chr>, yrdln <chr>, ydstogo <dbl>,
#> #   ydsnet <dbl>, desc <chr>, play_type <chr>, yards_gained <dbl>, …

# \dontshow{
# Close open connections for R CMD Check
future::plan("sequential")
# }
# }