From d07f9a799c5f655f742d73d1f54104acfd9f728a Mon Sep 17 00:00:00 2001 From: mrcaseb Date: Tue, 3 Dec 2024 20:18:42 +0100 Subject: [PATCH 1/2] Fix `receiving_air_yards` --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/calculate_stats.R | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bbfc98b3..b9ec4f7e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: nflfastR Title: Functions to Efficiently Access NFL Play by Play Data -Version: 5.0.0 +Version: 5.0.0.9000 Authors@R: c(person(given = "Sebastian", family = "Carl", diff --git a/NEWS.md b/NEWS.md index 656ed997..bcad6bd1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# nflfastR (development version) + +- Fixed a bug where `calculate_stats()` incorrectly counted `receiving_air_yards`. (#500) + # nflfastR 5.0.0 ## Major Changes diff --git a/R/calculate_stats.R b/R/calculate_stats.R index f57017c7..9942cd57 100644 --- a/R/calculate_stats.R +++ b/R/calculate_stats.R @@ -267,7 +267,7 @@ calculate_stats <- function(seasons = nflreadr::most_recent_season(), # cannot appear more than once per play. # If this ever changes, we can use pbp instead. receiving_air_yards = if (.env$stat_type == "player"){ - sum( (stat_id %in% 21:22) * dplyr::first(.data$team_play_air_yards)) + sum( (stat_id %in% 21:22) * .data$team_play_air_yards ) } else .data$passing_air_yards, receiving_yards_after_catch = sum((stat_id == 113) * yards), receiving_first_downs = sum((stat_id %in% 21:22) & has_id(4, team_stats)), From ba00e9e7028f66e96c67ccbcd5a9b00f2510f0b6 Mon Sep 17 00:00:00 2001 From: mrcaseb Date: Tue, 3 Dec 2024 20:29:11 +0100 Subject: [PATCH 2/2] sum air yards of all targets, not only completions --- R/calculate_stats.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/calculate_stats.R b/R/calculate_stats.R index 9942cd57..17657dd1 100644 --- a/R/calculate_stats.R +++ b/R/calculate_stats.R @@ -267,7 +267,7 @@ calculate_stats <- function(seasons = nflreadr::most_recent_season(), # cannot appear more than once per play. # If this ever changes, we can use pbp instead. receiving_air_yards = if (.env$stat_type == "player"){ - sum( (stat_id %in% 21:22) * .data$team_play_air_yards ) + sum( (stat_id == 115) * .data$team_play_air_yards ) } else .data$passing_air_yards, receiving_yards_after_catch = sum((stat_id == 113) * yards), receiving_first_downs = sum((stat_id %in% 21:22) & has_id(4, team_stats)),