Skip to content

Commit

Permalink
Update penalty_type parser
Browse files Browse the repository at this point in the history
also update the description of penalty_type
  • Loading branch information
mrcaseb committed Mar 16, 2021
1 parent 94f3592 commit d564c06
Show file tree
Hide file tree
Showing 7 changed files with 10 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.9014
Version: 4.0.0.9015
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)

# nflfastR 4.0.0

Expand Down
9 changes: 5 additions & 4 deletions R/helper_add_nflscrapr_mutations.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ 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)") %>%
# For some reason Face Mask penalties include the string (15 Yards)
# Seb thought it's ok to drop that with the next two lines
stringr::str_remove("\\(.+\\)") %>%
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 d564c06

Please sign in to comment.