Skip to content

Commit 0489133

Browse files
authored
Merge pull request #589 from nflverse/new-raw-pbp
Redirect nflfastR to load raw pbp from nflverse-pbp releases
2 parents cfd00ef + 5d78e7d commit 0489133

4 files changed

Lines changed: 26 additions & 21 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
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.2.0.9011
4+
Version: 5.2.0.9012
55
Authors@R: c(
66
person("Sebastian", "Carl", , "mrcaseb@gmail.com", role = "aut"),
77
person("Ben", "Baldwin", , "bbaldwin206@gmail.com", role = c("cre", "aut")),

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
- Fixed a bug where `fixed_drive` did not increment after a muffed blocked field goal attempt. Yes this happened in `"2025_10_NO_CAR"`, play id 2504. (#567)
66
- nflfastR stopped supporting the 1999 and 2000 seasons because of inconsistent data sources. Data is still available through `load_pbp()` but we will not fix any issues related to those old seasons anymore. It's possible to install nflfastR v5.2.0 (with `pak::pak("nflverse/nflfastR@v5.2.0")`) to parse those seasons if necessary. (#568)
77
- Implemented a fresh approach to compute `play_type` based on `play_type_nfl` for faster and more consistent output. (#568)
8-
- Fixed a bug where nflfastR overrode the kickoff_attempt variable in the event of a penalty on a kickoff. (#569)
8+
- Fixed a bug where nflfastR overwrote the kickoff_attempt variable in the event of a penalty on a kickoff. (#569)
99
- Added various definitions of 'explosive' plays to the output of `calculate_stats()`. It counts passes, runs, and receptions with 10+, 20+, 40+ yards gained as well as 12+ yard runs and 16+ yard passes. (#573)
1010
- Added several punting stats to the output of `calculate_stats()`. (#574)
1111
- Added overall fumble counters to the output of `calculate_stats()` because it was missing some edge case fumbles on offense. (#575)
1212
- The `play_type` variable now possibly shows `"pass"` or `"run"` on 2 point conversion plays with a post-snap penalty enforced between downs. This is different from `play_type_nfl` (which will show `"PENALTY"` in these cases). (#579)
1313
- Fixed bug where `calculate_stats()` counted fumble recoveries in `fumble_recovery_yards_own` and `fumble_recovery_yards_opp` instead of the corresponding yards. (#584)
1414
- Fixed bug where `calculate_stats()` counted some blocked punts as punt attempts that officially do not count as punt attempts. (#584)
1515
- Fixed bug where `calculate_stats()` overcounted first downs in some edge cases. (#587)
16+
- nflfastR now loads raw play-by-play data from season based releases in the `nflverse/nflverse-pbp` GitHub repository. The legacy repository `nflverse/nflfastR-raw` is deprecated and won't update in future seasons. This means that previous nflfastR versions won't be able to download 2026+ seasons! (#589)
1617

1718
# nflfastR 5.2.0
1819

R/save_raw_pbp.R

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,21 @@ save_raw_pbp <- function(
6767
dir.create,
6868
FUN.VALUE = logical(1L)
6969
)
70-
to_load <- file.path(
71-
"https://raw.githubusercontent.com/nflverse/nflfastR-raw/master/raw",
72-
seasons,
73-
paste0(game_ids, ".rds"),
74-
fsep = "/"
75-
)
70+
to_load <- raw_pbp_urls(game_ids)
7671
save_to <- file.path(
7772
dir,
7873
seasons,
7974
paste0(game_ids, ".rds")
8075
)
81-
curl::multi_download(to_load, save_to)
76+
dl <- curl::multi_download(to_load, save_to)
77+
failed <- dl$status_code != 200
78+
if (any(failed)) {
79+
cli::cli_alert_danger(
80+
"Failed to download: {.var {game_ids[failed]}}"
81+
)
82+
file.remove(save_to[failed])
83+
}
84+
dl
8285
}
8386

8487
#' Compute Missing Raw PBP Data on Local Filesystem

R/utils.R

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,7 @@ load_raw_game <- function(
118118
# cli::cli_progress_step("Load locally from {.path {local_file}}")
119119
raw <- readRDS(local_file)
120120
} else {
121-
to_load <- file.path(
122-
"https://raw.githubusercontent.com/nflverse/nflfastR-raw/master/raw",
123-
season,
124-
paste0(game_id, ".rds"),
125-
fsep = "/"
126-
)
121+
to_load <- raw_pbp_urls(game_id)
127122
raw <- nflreadr::rds_from_url(to_load)
128123
}
129124

@@ -193,12 +188,7 @@ fetch_raw <- function(
193188
season <- substr(game_id, 1, 4)
194189

195190
if (is.null(dir)) {
196-
to_load <- file.path(
197-
"https://raw.githubusercontent.com/nflverse/nflfastR-raw/master/raw",
198-
season,
199-
paste0(game_id, ".rds"),
200-
fsep = "/"
201-
)
191+
to_load <- raw_pbp_urls(game_id)
202192

203193
fetched <- curl::curl_fetch_memory(to_load)
204194

@@ -347,3 +337,14 @@ check_for_dropped_seasons <- function(game_ids) {
347337
}
348338
game_ids
349339
}
340+
341+
raw_pbp_urls <- function(game_ids) {
342+
# pattern
343+
# https://github.com/nflverse/nflverse-pbp/releases/download/{season}/{game_id}.rds
344+
file.path(
345+
"https://github.com/nflverse/nflverse-pbp/releases/download",
346+
paste0("raw_pbp_", substr(game_ids, 1, 4)),
347+
paste0(game_ids, ".rds"),
348+
fsep = "/"
349+
)
350+
}

0 commit comments

Comments
 (0)