Skip to content

Commit 363344d

Browse files
authored
Merge pull request #503 from nflverse/catch-na-spreads
Catch missing `spread_line` data
2 parents 1741e87 + 42da8e5 commit 363344d

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: nflfastR
33
Title: Functions to Efficiently Access NFL Play by Play Data
4-
Version: 5.0.0.9000
4+
Version: 5.0.0.9001
55
Authors@R:
66
c(person(given = "Sebastian",
77
family = "Carl",

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# nflfastR (development version)
22

33
- Fixed a bug where `calculate_stats()` incorrectly counted `receiving_air_yards`. (#500)
4+
- Fixed a bug where `vegas_wp` variables were broken when `spread_line` data was missing. (#503)
45

56
# nflfastR 5.0.0
67

R/helper_add_ep_wp.R

+18
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,24 @@ wp_spread_model_select <- function(pbp) {
196196
}
197197
prepare_wp_data <- function(pbp) {
198198

199+
if (any(is.na(pbp$spread_line))){
200+
broken_games <- pbp %>%
201+
dplyr::filter(is.na(.data$spread_line)) %>%
202+
dplyr::pull(game_id) %>%
203+
unique() %>%
204+
sort()
205+
cli::cli_alert_danger(
206+
"The following game{?s} {?is/are} missing valid spread lines: {.val {broken_games}}."
207+
)
208+
cli::cli_alert_warning(
209+
"nflfastR will manually set the spread for the home team to {.val 1.5} points!"
210+
)
211+
cli::cli_alert_warning(
212+
"If you see this, please reach out to the package maintainers {.url https://github.com/nflverse/nflfastR/issues}"
213+
)
214+
pbp$spread_line[is.na(pbp$spread_line)] <- 1.5
215+
}
216+
199217
pbp <- pbp %>%
200218
dplyr::group_by(.data$game_id) %>%
201219
dplyr::mutate(

nflfastR.Rproj

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Version: 1.0
2+
ProjectId: e1e14382-386c-49b3-9b3f-206a4cc98503
23

34
RestoreWorkspace: Default
45
SaveWorkspace: Default

0 commit comments

Comments
 (0)