Skip to content

Commit

Permalink
Load Player Stats Defense
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcaseb committed Aug 17, 2023
1 parent f34d5df commit f35ca99
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
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.3.2.07
Version: 1.3.2.09
Authors@R: c(
person("Tan", "Ho", , "[email protected]", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0001-8388-5155")),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ etc falsely returned last season after March 15th early in the month. (1.3.2.03)
- Added `.for_cran()` to limit parallelization in CRAN examples and tests (1.3.2.07)
- `nflverse_sitrep()` and friends now return a list of sitrep attributes instead of just printing to console.
- `make_nflverse_data_class()` now uses `data.table::setattr()` to set attributes and retain data.table pointer (v1.3.2.08)
- `nflreadr::load_player_stats()` now accepts `stat_type = "defense"` and loads defensive player stats computed with `nflfastR::calculate_player_stats_def()`. (v1.3.2.09) (#)

# nflreadr 1.3.2

Expand Down
7 changes: 4 additions & 3 deletions R/load_player_stats.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Load Player Level Weekly Stats
#'
#' @param seasons a numeric vector of seasons to return, defaults to most recent season. If set to `TRUE`, returns all available data.
#' @param stat_type one of `offense` or `kicking`
#' @param stat_type one of `"offense"`, `"defense"`, or `"kicking"`
#' @param file_type One of `c("rds", "qs", "csv", "parquet")`. Can also be set globally with
#' `options(nflreadr.prefer)`
#'
Expand All @@ -22,18 +22,19 @@
#'
#' @export
load_player_stats <- function(seasons = most_recent_season(),
stat_type = c("offense","kicking"), # defense, punting, other as added
stat_type = c("offense", "defense", "kicking"), # defense, punting, other as added
file_type = getOption("nflreadr.prefer", default = "rds")){

if(!isTRUE(seasons)) {stopifnot(is.numeric(seasons),
seasons >=1999,
seasons <= most_recent_season())}

file_type <- rlang::arg_match0(file_type, c("rds", "csv","qs", "parquet"))
stat_type <- rlang::arg_match0(stat_type, c("offense","kicking"))
stat_type <- rlang::arg_match0(stat_type, c("offense", "defense", "kicking"))

base_name <- switch(stat_type,
"offense" = "player_stats.",
"defense" = "player_stats_def.",
"kicking" = "player_stats_kicking.")

url <- paste0("https://github.com/nflverse/nflverse-data/releases/download/player_stats/",base_name,file_type)
Expand Down
4 changes: 2 additions & 2 deletions man/load_player_stats.Rd

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

3 changes: 3 additions & 0 deletions tests/testthat/test-nflverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,20 @@ test_that("load_player_stats", {
ps_all <- load_player_stats(seasons = TRUE)

kick <- load_player_stats(2020, stat_type = "kicking")
defense <- load_player_stats(2022, stat_type = "defense")

expect_s3_class(ps, "nflverse_data")
expect_s3_class(ps_2020, "nflverse_data")
expect_s3_class(ps_csv, "nflverse_data")
expect_s3_class(ps_all, "nflverse_data")
expect_s3_class(kick, "nflverse_data")
expect_s3_class(defense, "nflverse_data")

expect_gt(nrow(ps_2020), 5000)
expect_gt(nrow(ps_csv), 5000)
expect_gt(nrow(ps_all), 110000)
expect_gt(nrow(kick), 500)
expect_gt(nrow(defense), 9800)
})

test_that("load_schedules", {
Expand Down

0 comments on commit f35ca99

Please sign in to comment.