Skip to content

Commit

Permalink
Merge pull request #224 from mrcaseb/fix-penalty-type
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcaseb authored Mar 22, 2021
2 parents d38eb07 + 66d866d commit 874c71b
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: nflfastR
Title: Functions to Efficiently Access NFL Play by Play Data
Version: 4.0.0.9015
Version: 4.0.0.9016
Authors@R:
c(person(given = "Sebastian",
family = "Carl",
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* `fixed_drive` now increments properly on onside kick recoveries (#215)
* `fixed_drive` no longer counts a muffed kickoff as a one-play drive on its own (#217)
* `fixed_drive` now properly increments after a safety (#219)
* Improved parser for `penalty_type` and updated the description of the variable to make more clear it's the first penalty that happened on a play. (#223)
* Heavy performance boost for the function `clean_pbp()`

# nflfastR 4.0.0
Expand Down
10 changes: 6 additions & 4 deletions R/helper_add_nflscrapr_mutations.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ add_nflscrapr_mutations <- function(pbp) {
penalty_type = dplyr::if_else(
.data$penalty == 1,
.data$play_description %>%
stringr::str_extract("PENALTY on (.){2,35},.+, [0-9]{1,2} yard(s),") %>%
stringr::str_extract(", (([:alpha:])+([:space:])?)+,") %>%
stringr::str_remove_all(",") %>%
stringr::str_trim(), NA_character_
stringr::str_extract("(?<=PENALTY on .{1,50}, ).{1,50}(?=, [0-9]{1,2} yard)") %>%
# Face Mask penalties include the yardage as string (either 5 Yards or 15 Yards)
# We remove the 15 Yards part and just keep the additional info if it's a
# 5 yard Face Mask penalty
stringr::str_remove("\\([0-9]{2}+ Yards\\)") %>%
stringr::str_squish(), NA_character_
),
# Make plays marked with down == 0 as NA:
down = dplyr::if_else(
Expand Down
2 changes: 1 addition & 1 deletion R/top-level_scraper.R
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@
#' \item{penalty_yards}{Yards gained (or lost) by the posteam from the penalty.}
#' \item{replay_or_challenge}{Binary indicator for whether or not a replay or challenge.}
#' \item{replay_or_challenge_result}{String indicating the result of the replay or challenge.}
#' \item{penalty_type}{String indicating the penalty type.}
#' \item{penalty_type}{String indicating the penalty type of the first penalty in the given play. Will be `NA` if `desc` is missing the type.}
#' \item{defensive_two_point_attempt}{Binary indicator whether or not the defense was able to have an attempt on a two point conversion, this results following a turnover.}
#' \item{defensive_two_point_conv}{Binary indicator whether or not the defense successfully scored on the two point conversion.}
#' \item{defensive_extra_point_attempt}{Binary indicator whether or not the defense was able to have an attempt on an extra point attempt, this results following a blocked attempt that the defense recovers the ball.}
Expand Down
2 changes: 1 addition & 1 deletion data-raw/variable_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
#' \item{penalty_yards}{Yards gained (or lost) by the posteam from the penalty.}
#' \item{replay_or_challenge}{Binary indicator for whether or not a replay or challenge.}
#' \item{replay_or_challenge_result}{String indicating the result of the replay or challenge.}
#' \item{penalty_type}{String indicating the penalty type.}
#' \item{penalty_type}{String indicating the penalty type of the first penalty in the given play. Will be `NA` if `desc` is missing the type.}
#' \item{defensive_two_point_attempt}{Binary indicator whether or not the defense was able to have an attempt on a two point conversion, this results following a turnover.}
#' \item{defensive_two_point_conv}{Binary indicator whether or not the defense successfully scored on the two point conversion.}
#' \item{defensive_extra_point_attempt}{Binary indicator whether or not the defense was able to have an attempt on an extra point attempt, this results following a blocked attempt that the defense recovers the ball.}
Expand Down
Binary file modified data/field_descriptions.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion man/fast_scraper.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 874c71b

Please sign in to comment.