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.
Arguments
- game_ids
Vector of character ids or a data frame including the variable
game_id
(see details for further information).- ...
Additional arguments passed to the scraping functions (for internal use)
- decode
If
TRUE
, the functiondecode_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.5.1.9001 ──
#> • 16:57:37 | 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...
#> ✔ 16:57:41 | Download finished. Adding variables...
#> ✔ 16:57:41 | added game variables
#> ✔ 16:57:43 | added nflscrapR variables
#> [16:57:43] 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.
#>
#> ✔ 16:57:44 | added ep variables
#> ✔ 16:57:44 | added air_yac_ep variables
#> [16:57:44] 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.
#>
#> [16:57:44] 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.
#>
#> ✔ 16:57:45 | added wp variables
#> ✔ 16:57:45 | added air_yac_wp variables
#> [16:57:45] 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.
#>
#> ✔ 16:57:45 | added cp and cpoe
#> ✔ 16:57:46 | added fixed drive variables
#> ✔ 16:57:47 | added series variables
#> • 16:57:47 | Cleaning up play-by-play...
#> ✔ 16:57:48 | Cleaning completed
#> ✔ 16:57:48 | added qb_epa
#> • 16:57:48 | Computing xyac...
#> [16:57:49] 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.
#>
#> ✔ 16:57:56 | added xyac variables
#> • 16:57:56 | Computing xpass...
#> [16:57:56] 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.
#>
#> ✔ 16:57:56 | added xpass and pass_oe
#> ✔ 16:57:56 | Decoding of player ids completed
#> ── DONE ────────────────────────────────────────────────────────────────────────
#> ── nflverse play by play ───────────────────────────────────────────────────────
#> ℹ Data updated: 2023-01-30 16:57:56 UTC
#> # A tibble: 353 × 372
#> play_id game_id old_g…¹ home_…² away_…³ seaso…⁴ week posteam poste…⁵ defteam
#> <dbl> <chr> <chr> <chr> <chr> <chr> <int> <chr> <chr> <chr>
#> 1 1 2018_2… 201902… LA NE POST 21 NA NA NA
#> 2 38 2018_2… 201902… LA NE POST 21 NE away LA
#> 3 67 2018_2… 201902… LA NE POST 21 NE away LA
#> 4 89 2018_2… 201902… LA NE POST 21 NE away LA
#> 5 111 2018_2… 201902… LA NE POST 21 NE away LA
#> 6 133 2018_2… 201902… LA NE POST 21 NE away LA
#> 7 155 2018_2… 201902… LA NE POST 21 NE away LA
#> 8 182 2018_2… 201902… LA NE POST 21 LA home NE
#> 9 204 2018_2… 201902… LA NE POST 21 LA home NE
#> 10 226 2018_2… 201902… LA NE POST 21 LA home NE
#> # … with 343 more rows, 362 more variables: 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 <dbl>, time <chr>, yrdln <chr>, ydstogo <dbl>,
#> # ydsnet <dbl>, desc <chr>, play_type <chr>, yards_gained <dbl>,
#> # shotgun <dbl>, no_huddle <dbl>, qb_dropback <dbl>, qb_kneel <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.5.1.9001 ──
#> • 16:57:56 | 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...
#> ✔ 16:58:01 | Download finished. Adding variables...
#> ✔ 16:58:02 | added game variables
#> ✔ 16:58:04 | added nflscrapR variables
#> ✔ 16:58:04 | added ep variables
#> ✔ 16:58:05 | added air_yac_ep variables
#> ✔ 16:58:05 | added wp variables
#> ✔ 16:58:05 | added air_yac_wp variables
#> ✔ 16:58:05 | added cp and cpoe
#> ✔ 16:58:07 | added fixed drive variables
#> ✔ 16:58:08 | added series variables
#> • 16:58:08 | Cleaning up play-by-play...
#> ✔ 16:58:08 | Cleaning completed
#> ✔ 16:58:09 | added qb_epa
#> • 16:58:09 | Computing xyac...
#> ✔ 16:58:18 | added xyac variables
#> • 16:58:19 | Computing xpass...
#> ✔ 16:58:19 | added xpass and pass_oe
#> ✔ 16:58:19 | Decoding of player ids completed
#> ── DONE ────────────────────────────────────────────────────────────────────────
#> ── nflverse play by play ───────────────────────────────────────────────────────
#> ℹ Data updated: 2023-01-30 16:58:19 UTC
#> # A tibble: 545 × 372
#> play_id game_id old_g…¹ home_…² away_…³ seaso…⁴ week posteam poste…⁵ defteam
#> <dbl> <chr> <chr> <chr> <chr> <chr> <int> <chr> <chr> <chr>
#> 1 1 2020_2… 202101… KC BUF POST 20 NA NA NA
#> 2 42 2020_2… 202101… KC BUF POST 20 BUF away KC
#> 3 57 2020_2… 202101… KC BUF POST 20 BUF away KC
#> 4 78 2020_2… 202101… KC BUF POST 20 BUF away KC
#> 5 102 2020_2… 202101… KC BUF POST 20 BUF away KC
#> 6 123 2020_2… 202101… KC BUF POST 20 BUF away KC
#> 7 145 2020_2… 202101… KC BUF POST 20 BUF away KC
#> 8 174 2020_2… 202101… KC BUF POST 20 BUF away KC
#> 9 207 2020_2… 202101… KC BUF POST 20 BUF away KC
#> 10 236 2020_2… 202101… KC BUF POST 20 BUF away KC
#> # … with 535 more rows, 362 more variables: 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 <dbl>, time <chr>, yrdln <chr>, ydstogo <dbl>,
#> # ydsnet <dbl>, desc <chr>, play_type <chr>, yards_gained <dbl>,
#> # shotgun <dbl>, no_huddle <dbl>, qb_dropback <dbl>, qb_kneel <dbl>, …
# \dontshow{
# Close open connections for R CMD Check
future::plan("sequential")
# }
# }