From c525c8df410726e9d5fd7ed355ae38cbb19147e1 Mon Sep 17 00:00:00 2001 From: Tan Date: Mon, 20 Jan 2025 11:57:56 -0500 Subject: [PATCH] clean up internal namespace and directly re-export load_pbp, load_player_stats --- NAMESPACE | 32 ++----------------------------- R/load_pbp.R | 12 ------------ R/load_player_stats.R | 30 ----------------------------- R/nflfastR-package.R | 37 ++++++++++++++++++++---------------- man/calculate_stats.Rd | 7 ++++++- man/load_pbp.Rd | 41 ---------------------------------------- man/load_player_stats.Rd | 36 ----------------------------------- 7 files changed, 29 insertions(+), 166 deletions(-) delete mode 100644 R/load_pbp.R delete mode 100644 R/load_player_stats.R delete mode 100644 man/load_pbp.Rd delete mode 100644 man/load_player_stats.Rd diff --git a/NAMESPACE b/NAMESPACE index bd8741de..433c3bd0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -24,24 +24,13 @@ export(nflverse_sitrep) export(report) export(save_raw_pbp) export(update_db) -import(dplyr) import(fastrmodels) -importFrom(cli,rule) -importFrom(curl,curl_fetch_memory) importFrom(data.table,"%between%") importFrom(data.table,"%chin%") importFrom(data.table,setDT) -importFrom(furrr,future_map) -importFrom(furrr,future_map_chr) -importFrom(furrr,future_map_dfr) -importFrom(future,plan) -importFrom(glue,glue) -importFrom(glue,glue_sql) -importFrom(janitor,clean_names) -importFrom(lifecycle,deprecated) -importFrom(mgcv,predict.bam) +importFrom(nflreadr,load_pbp) +importFrom(nflreadr,load_player_stats) importFrom(nflreadr,nflverse_sitrep) -importFrom(progressr,progressor) importFrom(rlang,":=") importFrom(rlang,.data) importFrom(rlang,.env) @@ -49,20 +38,3 @@ importFrom(rlang,dots_list) importFrom(rlang,inform) importFrom(stats,na.omit) importFrom(stats,predict) -importFrom(stringr,str_detect) -importFrom(stringr,str_extract) -importFrom(stringr,str_extract_all) -importFrom(stringr,str_length) -importFrom(stringr,str_remove_all) -importFrom(stringr,str_replace_all) -importFrom(stringr,str_split) -importFrom(stringr,str_sub) -importFrom(stringr,str_trim) -importFrom(tibble,as_tibble) -importFrom(tibble,tibble) -importFrom(tidyr,unnest) -importFrom(tidyr,unnest_wider) -importFrom(tidyselect,any_of) -importFrom(tidyselect,ends_with) -importFrom(utils,packageVersion) -importFrom(xgboost,getinfo) diff --git a/R/load_pbp.R b/R/load_pbp.R deleted file mode 100644 index 798d27d7..00000000 --- a/R/load_pbp.R +++ /dev/null @@ -1,12 +0,0 @@ -#' @inherit nflreadr::load_pbp -#' @inheritDotParams nflreadr::load_pbp -#' @param ... Arguments passed on to nflreadr::load_pbp -#' @examples -#' \donttest{ -#' try({# to avoid CRAN test problems -#' pbp <- load_pbp(2019:2020) -#' dplyr::glimpse(pbp) -#' }) -#' } -#' @export -load_pbp <- function(...) nflreadr::load_pbp(...) diff --git a/R/load_player_stats.R b/R/load_player_stats.R deleted file mode 100644 index 34b2596f..00000000 --- a/R/load_player_stats.R +++ /dev/null @@ -1,30 +0,0 @@ -#' @inherit nflreadr::load_player_stats -#' @inheritDotParams nflreadr::load_player_stats -#' @param ... Arguments passed on to nflreadr::load_player_stats -#' @seealso The function [calculate_player_stats()] and the corresponding examples -#' on [the nflfastR website](https://www.nflfastr.com/articles/nflfastR.html#example-11-replicating-official-stats) -#' @examples -#' \donttest{ -#' try({# to avoid CRAN test problems -#' stats <- load_player_stats() -#' dplyr::glimpse(stats) -#' }) -#' } -#' @export -load_player_stats <- function(...){ - - # if the dots are empty, we now have the same behavior like nflreadr which - # differs from the previous versions where it was "load all seasons" - if (rlang::is_empty(list(...))){ - cli::cli_warn( - c("We have changed the behavior of {.var load_player_stats()} as of nflfastR 4.3.0.", - "Calling it without an argument will return the current season only instead of all available seasons.", - "Please try {.var load_player_stats(seasons = TRUE)} to get all seasons." - ), - .frequency = "regularly", .frequency_id = "player_stats_warning" - ) - } - - # if dots are not empty, use them in nflreadr - nflreadr::load_player_stats(...) -} diff --git a/R/nflfastR-package.R b/R/nflfastR-package.R index 9a014196..a4c966ae 100644 --- a/R/nflfastR-package.R +++ b/R/nflfastR-package.R @@ -103,25 +103,30 @@ # The following block is used by usethis to automatically manage # roxygen namespace tags. Modify with care! ## usethis namespace: start -#' @import dplyr #' @import fastrmodels -#' @importFrom cli rule -#' @importFrom curl curl_fetch_memory +#' @importFrom nflreadr load_pbp load_player_stats +#' @export load_pbp +#' @export load_player_stats +#' @importFrom magrittr %>% #' @importFrom data.table setDT %between% %chin% -#' @importFrom furrr future_map_chr future_map_dfr future_map -#' @importFrom future plan -#' @importFrom glue glue glue_sql -#' @importFrom janitor clean_names -#' @importFrom lifecycle deprecated -#' @importFrom mgcv predict.bam -#' @importFrom progressr progressor -#' @importFrom rlang .data inform dots_list := .env +#' @importFrom rlang .data inform dots_list := .env %||% #' @importFrom stats predict na.omit -#' @importFrom stringr str_sub str_replace_all str_length str_extract str_detect str_trim str_remove_all str_split str_extract_all -#' @importFrom tibble as_tibble tibble -#' @importFrom tidyr unnest_wider unnest -#' @importFrom tidyselect any_of ends_with #' @importFrom utils packageVersion -#' @importFrom xgboost getinfo ## usethis namespace: end NULL + +# @import dplyr +# @importFrom cli rule +# @importFrom curl curl_fetch_memory +# @importFrom furrr future_map_chr future_map_dfr future_map +# @importFrom future plan +# @importFrom glue glue glue_sql +# @importFrom janitor clean_names +# @importFrom lifecycle deprecated +# @importFrom mgcv predict.bam +# @importFrom progressr progressor +# @importFrom stringr str_sub str_replace_all str_length str_extract str_detect str_trim str_remove_all str_split str_extract_all +# @importFrom tibble as_tibble tibble +# @importFrom tidyr unnest_wider unnest +# @importFrom tidyselect any_of ends_with +# @importFrom xgboost getinfo diff --git a/man/calculate_stats.Rd b/man/calculate_stats.Rd index 511bfe66..b69da445 100644 --- a/man/calculate_stats.Rd +++ b/man/calculate_stats.Rd @@ -8,7 +8,8 @@ calculate_stats( seasons = nflreadr::most_recent_season(), summary_level = c("season", "week"), stat_type = c("player", "team"), - season_type = c("REG", "POST", "REG+POST") + season_type = c("REG", "POST", "REG+POST"), + pbp = NULL ) } \arguments{ @@ -23,6 +24,10 @@ data since 1999.} \item{season_type}{One of \code{"REG"}, \code{"POST"}, or \code{"REG+POST"}. Filters data to regular season ("REG"), post season ("POST") or keeps all data. Only applied if \code{summary_level} == \code{"season"}.} + +\item{pbp}{advanced: a dataframe of pbp data (as created by \code{nflreadr::load_pbp()}) +that can be filtered in advance to create summary stats for a given subset of +pbp data. Defaults to \code{NULL} which will run \code{nflreadr::load_pbp(seasons)} internally.} } \value{ A tibble of player/team stats summarized by season/week. diff --git a/man/load_pbp.Rd b/man/load_pbp.Rd deleted file mode 100644 index 2d457a1c..00000000 --- a/man/load_pbp.Rd +++ /dev/null @@ -1,41 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/load_pbp.R -\name{load_pbp} -\alias{load_pbp} -\title{Load Play By Play} -\usage{ -load_pbp(...) -} -\arguments{ -\item{...}{ - Arguments passed on to \code{\link[nflreadr:load_pbp]{nflreadr::load_pbp}} - \describe{ - \item{\code{seasons}}{A numeric vector of 4-digit years associated with given NFL seasons - defaults to latest season. If set to \code{TRUE}, returns all available data since 1999.} - \item{\code{file_type}}{One of \code{c("rds", "qs", "csv", "parquet")}. Can also be set globally with -\code{options(nflreadr.prefer)}} - }} -} -\value{ -The complete nflfastR dataset as returned by \code{nflfastR::build_nflfastR_pbp()} -(see below) for all given \code{seasons} -} -\description{ -Loads play by play seasons from the \href{https://github.com/nflverse/nflverse-data}{nflverse-data repository} -} -\examples{ -\donttest{ -try({# to avoid CRAN test problems -pbp <- load_pbp(2019:2020) -dplyr::glimpse(pbp) -}) -} -} -\seealso{ -\url{https://nflreadr.nflverse.com/articles/dictionary_pbp.html} for a web version of the data dictionary - -\code{\link[nflreadr]{dictionary_pbp}} for the data dictionary bundled as a package dataframe - -\url{https://www.nflfastr.com/reference/build_nflfastR_pbp.html} for the nflfastR function \code{nflfastR::build_nflfastR_pbp()} - -Issues with this data should be filed here: \url{https://github.com/nflverse/nflverse-pbp} -} diff --git a/man/load_player_stats.Rd b/man/load_player_stats.Rd deleted file mode 100644 index 42cc6479..00000000 --- a/man/load_player_stats.Rd +++ /dev/null @@ -1,36 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/load_player_stats.R -\name{load_player_stats} -\alias{load_player_stats} -\title{Load Player Level Weekly Stats} -\usage{ -load_player_stats(...) -} -\arguments{ -\item{...}{ - Arguments passed on to \code{\link[nflreadr:load_player_stats]{nflreadr::load_player_stats}} - \describe{ - \item{\code{seasons}}{a numeric vector of seasons to return, defaults to most recent season. If set to \code{TRUE}, returns all available data.} - \item{\code{stat_type}}{one of \code{"offense"}, \code{"defense"}, or \code{"kicking"}} - \item{\code{file_type}}{One of \code{c("rds", "qs", "csv", "parquet")}. Can also be set globally with -\code{options(nflreadr.prefer)}} - }} -} -\value{ -A tibble of week-level player statistics that aims to match NFL official box scores. -} -\description{ -Load Player Level Weekly Stats -} -\examples{ -\donttest{ -try({# to avoid CRAN test problems -stats <- load_player_stats() -dplyr::glimpse(stats) -}) -} -} -\seealso{ -The function \code{\link[=calculate_player_stats]{calculate_player_stats()}} and the corresponding examples -on \href{https://www.nflfastr.com/articles/nflfastR.html#example-11-replicating-official-stats}{the nflfastR website} -}