Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch invalid roof values in load_schedules() #218

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: nflreadr
Title: Download 'nflverse' Data
Version: 1.4.0.02
Version: 1.4.0.03
Authors@R: c(
person("Tan", "Ho", , "tan@tanho.ca", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0001-8388-5155")),
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
## Changelog

- `%c%` internal helper now uses `data.table::fifelse()` to avoid falsely converting dates to integers. (#214)
- `load_schedules()` cleans the `roof` variable in order to avoid nflverse model issues. (#218)

---

7 changes: 7 additions & 0 deletions R/load_schedules.R
Original file line number Diff line number Diff line change
@@ -25,5 +25,12 @@ load_schedules <- function(seasons = TRUE){
seasons = seasons,
nflverse = TRUE,
nflverse_type = "games and schedules")
# nflfastR and nfl4th use the "roof" variable in several models
# These models expect one of c("indoors", "closed", "outdoors", "open", "retractable") or NA
# We ran into problems where roof was empty or something else several time
# So we catch these cases here and change invalid data to NA
valid_roof_values <- c("indoors", "closed", "dome", "outdoors", "open", "retractable", NA_character_)
out$roof[!out$roof %in% valid_roof_values] <- NA_character_

return(out)
}
3 changes: 3 additions & 0 deletions tests/testthat/test-nflverse.R
Original file line number Diff line number Diff line change
@@ -69,6 +69,9 @@ test_that("load_schedules", {

expect_gt(nrow(schedules), 6000)

valid_roof_values <- c("indoors", "closed", "dome", "outdoors", "open", "retractable", NA_character_)
expect_true(all(schedules$roof %in% valid_roof_values))

expect_error(load_schedules("2020"))

sched_2020 <- load_schedules(2020)