Skip to content

Commit 0f6b908

Browse files
authored
Merge pull request #268 from nflverse/nflreadr-for-player-stats
Use nflreadr for `load_player_stats`
2 parents b3d5c15 + 9ff4979 commit 0f6b908

File tree

4 files changed

+42
-31
lines changed

4 files changed

+42
-31
lines changed

DESCRIPTION

+2-2
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: 4.2.0.9007
4+
Version: 4.2.0.9008
55
Authors@R:
66
c(person(given = "Sebastian",
77
family = "Carl",
@@ -54,7 +54,7 @@ Imports:
5454
mgcv,
5555
nflreadr (>= 1.0.0),
5656
progressr (>= 0.6.0),
57-
rlang,
57+
rlang (>= 0.4.7),
5858
stringr (>= 1.3.0),
5959
tibble (>= 3.0),
6060
tidyr (>= 1.0.0),

NEWS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
* Fixed a minor bug in the console output of `update_db()`
44
* Add nflreadr to dependecies and drop lubridate and magrittr dependency
5-
* The function `load_pbp()` now calls `nflreadr::load_pbp()` internally. Therefore the argument `qs` has been deprecated. It will be removed in a future release.
5+
* The functions `load_pbp()` and `load_player_stats()` now call `nflreadr::load_pbp()` and `nflreadr::load_player_stats()` respectively. Therefore the argument `qs` has been deprecated in both functions. It will be removed in a future release. Running `load_player_stats()` without any argument will now return player stats of the current season only (the default in `nflreadr`).
66
* The deprecated arguments `source` and `pp` in the functions `fast_scraper_*()` and `build_nflfastR_pbp()` have been removed
77
* Added the variables `racr` ("Receiver Air Conversion Ratio"), `target_share`, `air_yards_share`, `wopr` ("Weighted Opportunity Rating") and `pacr` ("Passing Air Conversion Ratio") to the output of `calculate_player_stats()`
88
* Fix for a handful of missing `receiver` names (#270)

R/load_player_stats.R

+24-21
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
#' Load Official Game Stats
2-
#'
3-
#' @description Loads weekly stats for all passers, rushers and receivers in the
4-
#' nflfastR play-by-play data from the 1999 season to the most recent season
5-
#'
6-
#' @param qs Whether to use the function [qs::qdeserialize()] for more efficient loading.
7-
#' @return Weekly stats for all passers, rushers and receivers in the nflfastR
8-
#' play-by-play data from the 1999 season to the most recent season
1+
#' @inherit nflreadr::load_player_stats
2+
#' @inheritDotParams nflreadr::load_player_stats
3+
#' @param qs `r lifecycle::badge("deprecated")` has no effect and will be
4+
#' removed in a future release.
5+
#' @param ... Arguments passed on to nflreadr::load_player_stats
96
#'
107
#' @seealso The function [calculate_player_stats()] and the corresponding examples
118
#' on [the nflfastR website](https://www.nflfastr.com/articles/nflfastR.html#example-11-replicating-official-stats)
@@ -15,21 +12,27 @@
1512
#' dplyr::glimpse(stats)
1613
#' }
1714
#' @export
18-
load_player_stats <- function(qs = FALSE) {
19-
20-
if (isTRUE(qs) && !is_installed("qs")) {
21-
cli::cli_abort("Package {.val qs} required for argument {.val qs = TRUE}. Please install it.")
15+
load_player_stats <- function(..., qs = lifecycle::deprecated()){
16+
if (lifecycle::is_present(qs)) {
17+
lifecycle::deprecate_warn(
18+
when = "4.3.0",
19+
what = "load_pbp(qs = )",
20+
details = cli::cli_text("The {.val qs} argument is deprecated and replaced by {.val file_type} - see {.code ?nflreadr::load_player_stats} for details.")
21+
)
2222
}
2323

24-
if (isTRUE(qs)) {
25-
.url <- "https://github.com/nflverse/nflfastR-data/blob/master/data/player_stats.qs?raw=true"
26-
out <- qs_from_url(.url)
27-
} else {
28-
.url <- "https://github.com/nflverse/nflfastR-data/blob/master/data/player_stats.rds?raw=true"
29-
con <- url(.url)
30-
out <- readRDS(con)
31-
close(con)
24+
# if the dots are empty, we now have the same behavior like nflreadr which
25+
# differs from the previous versions where it was "load all seasons"
26+
if (rlang::is_empty(list(...))){
27+
cli::cli_warn(
28+
c("We have changed the behavior of {.var load_player_stats()} as of nflfastR 4.3.0.",
29+
"Calling it without an argument will return the current season only instead of all available seasons.",
30+
"Please try {.var load_player_stats(seasons = TRUE)} to get all seasons."
31+
),
32+
.frequency = "regularly", .frequency_id = "player_stats_warning"
33+
)
3234
}
3335

34-
return(out)
36+
# if dots are not empty, use them in nflreadr
37+
nflreadr::load_player_stats(...)
3538
}

man/load_player_stats.Rd

+15-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)