From 487c1a246866b982f2409e5e13b5608ef47d505b Mon Sep 17 00:00:00 2001 From: Manny Martinez Date: Mon, 7 Aug 2023 08:07:19 -0400 Subject: [PATCH] Added playerstats_def dictionary (#192) * Added playerstats_def dictionary * version and news bullet * export dictionary and redocument * add vignette * avoid cross ref warning --------- Co-authored-by: Sebastian Carl --- DESCRIPTION | 4 +-- NEWS.md | 1 + R/data.R | 8 ++++++ data-raw/build_data_dictionaries.R | 4 +++ data-raw/dictionary_playerstats_def.csv | 23 +++++++++++++++++ data/dictionary_player_stats_def.rda | Bin 0 -> 838 bytes man/csv_from_url.Rd | 3 +-- man/dictionary_player_stats_def.Rd | 21 ++++++++++++++++ vignettes/dictionary_player_stats_def.Rmd | 29 ++++++++++++++++++++++ 9 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 data-raw/dictionary_playerstats_def.csv create mode 100644 data/dictionary_player_stats_def.rda create mode 100644 man/dictionary_player_stats_def.Rd create mode 100644 vignettes/dictionary_player_stats_def.Rmd diff --git a/DESCRIPTION b/DESCRIPTION index acc7f65a..ac4074b4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: nflreadr Title: Download 'nflverse' Data -Version: 1.3.2.05 +Version: 1.3.2.06 Authors@R: c( person("Tan", "Ho", , "tan@tanho.ca", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0001-8388-5155")), @@ -48,4 +48,4 @@ Config/testthat/edition: 3 Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 diff --git a/NEWS.md b/NEWS.md index 01407aa6..05de62cf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,7 @@ a moving target 🙃 (1.3.2.01) etc falsely returned last season after March 15th early in the month. (1.3.2.03) - Clarified description of the `"special"` variable in the play-by-play data dictionary. (1.3.2.04) (#189) - `nflreadr::nflverse_game_id()` accepts old team abbreviations and outputs useful errors. (1.3.2.05) (#191) +- Added `dictionary_player_stats_def` (thank you @mpcen!) (1.3.2.06) (#192) # nflreadr 1.3.2 diff --git a/R/data.R b/R/data.R index 8bf70122..d374b3aa 100644 --- a/R/data.R +++ b/R/data.R @@ -14,6 +14,14 @@ #' @seealso "dictionary_player_stats" +#' Data Dictionary: Player Stats Defense +#' +#' A dataframe containing the data dictionary for [`load_player_stats()`] +#' +#' @seealso `vignette("Data Dictionary - Player Stats Defense")` +#' @seealso +"dictionary_player_stats_def" + #' Data Dictionary: Fantasy Player IDs #' #' A dataframe containing the data dictionary for [`load_ff_playerids()`] diff --git a/data-raw/build_data_dictionaries.R b/data-raw/build_data_dictionaries.R index 10669b04..1d681deb 100644 --- a/data-raw/build_data_dictionaries.R +++ b/data-raw/build_data_dictionaries.R @@ -8,6 +8,10 @@ dictionary_player_stats <- read.csv("data-raw/dictionary_playerstats.csv") |> dplyr::mutate_all(stringr::str_squish) usethis::use_data(dictionary_player_stats, overwrite = TRUE) +dictionary_player_stats_def <- read.csv("data-raw/dictionary_playerstats_def.csv") |> + dplyr::mutate_all(stringr::str_squish) +usethis::use_data(dictionary_player_stats_def, overwrite = TRUE) + dictionary_ff_playerids <- read.csv("data-raw/dictionary_ff_playerids.csv") |> dplyr::mutate_all(stringr::str_squish) usethis::use_data(dictionary_ff_playerids, overwrite = TRUE) diff --git a/data-raw/dictionary_playerstats_def.csv b/data-raw/dictionary_playerstats_def.csv new file mode 100644 index 00000000..32bfe2f5 --- /dev/null +++ b/data-raw/dictionary_playerstats_def.csv @@ -0,0 +1,23 @@ +field,data_type,description +def_tackles,numeric,Total number of tackles for this player +def_tackles_solo,numeric,Total number of solo tackles for this player +def_tackles_with_assist,numeric,Number of tackles this player had with an assisted tackle +def_tackle_assists,numeric,Number of assisted tackles for this player +def_tackles_for_loss,numeric,Number of tackles for loss (TFL) for this player +def_tackles_for_loss_yards,numeric,Yards lost from TFLs involving this player +def_fumbles_forced,numeric,Number of times a fumble was forced from this player +def_sacks,numeric,Number of sacks form this player +def_sack_yards,numeric,Yards lost from sacks forced by this player +def_qb_hits,numeric,Number of QB hits from this player (should not include plays where the QB was sacked) +def_interceptions,numeric,Number of interceptions forced by this player +def_interception_yards,numeric,yards gained/lost by interception returns from this player +def_pass_defended,numeric,Number of passes defended/broken up by this player +def_tds,numeric,Number of defensive touchdowns scored by this player +def_fumbles,numeric,Number of fumbles by this player +def_fumble_recovery_own,numeric,Number of times a player's team fumbled the ball and this player recovered +def_fumble_recovery_yards_own,numeric,Number of yards gained/lost from fumble recoveries that happened because the player's team fumbled the ball and this player recovered the fumble on that same play +def_fumble_recovery_opp,numeric,Number of times a player's opponent fumbled the ball and this player recovered +def_fumble_recovery_yards_opp,numeric,Number of yards gained/lost from fumble recoveries that happened because the player's opponent fumbled the ball and this player recovered the fumble on that same play +def_safety,numeric,Number of times this player forced a defensive safety +def_penalty,numeric,Number of times this player was penalized defensively +def_penalty_yards,numeric,Number of penalty yards for this player defensively \ No newline at end of file diff --git a/data/dictionary_player_stats_def.rda b/data/dictionary_player_stats_def.rda new file mode 100644 index 0000000000000000000000000000000000000000..9c5e4723aa95488721ecbf0ce50dce7d753d2933 GIT binary patch literal 838 zcmV-M1G)S{T4*^jL0KkKSrgyfi2woF|Iz-teVRc3-Y^vvHekQ+|FA#+5dZ)X00Gbg zdEnW#qJTtAQ`E>b&@>GLL686gKs`)N4?-FaGGx(+X`z6c7@9Q6h#4478fk_v007aT13)wYXwVKaWYLIep@5ngnl#CX85m6(X@nUtksz7~n;>eF)X-y4(U1%T zVrjJ*4K!#fofd17#gIYh+J)GqB4SJP_wJ+}zIZQ4gpr8B)bCnCGoVEF!=cMW0xtV3 zzjr+HUnrsrX_T>zH;J@0Vi#aS1_>?A5DiI?(n3e0?|?-ZE{j3GFK#to$FwuL;Hky$ zc5kk^PJ7r%g~2#1WLeO5qPl05@TDlr_7X@iCQ-N`NWvQ?4B0$uJPFG7K5-zptpv<% zdt;C0P^A|Y2V`AmO_Z&!GpKjUdM1vKbi!QN9;5g5fm;D}lPAez6wM;*t^_d049!Gw zx$OB?BHxD|nMP09^MNF}csezxNi5H1lICakk{M4F&#qN#|JqH=&QjFQ^l z;XY>^;c&vbSQ1z)3yB~nAujYK=6CXm<@3c@TJLI9z{0Pudt0*IbU zNX2>oNj{x21ZWmk$dG|v(x?!E1t9sPd+XUELb23PMSD;_k|6(`OM++Bb;+SEN=Yz+ z*v1nShSCDkK*UrP&=_Jv6E=-K%r+8+(YK>v+UrOdCEPl>i&W9?V4xT__(IHShX#YX z#EMTnf=1o2RTRl-78x;9c#(KuK>?mdZ6yJT9E6siPP(D68yZcMB67Ok+!*9k%Rtmd zR?1QWDTxf#65L7^TMk_1S_J|WhlCf}f}l|Bi4mD3g1Q`GDiayJW@L^?S-Zg3_BGa` zF}&<#a+X~#8<_xu2IuF(KAPk-peTSY&CVV__}C|27x}YmS3$8zB>gQBp_(Sr6i);=c5F}x`^8mO-s})7?r*Q6v$WhHUOcp;`0%V0Nr{|ph QV;}gtk}1N3fS&&3NJtZKIRF3v literal 0 HcmV?d00001 diff --git a/man/csv_from_url.Rd b/man/csv_from_url.Rd index cbd4086e..74ca6dfd 100644 --- a/man/csv_from_url.Rd +++ b/man/csv_from_url.Rd @@ -19,8 +19,7 @@ csv_from_url(...) \item{\code{nrows}}{ The maximum number of rows to read. Unlike \code{read.table}, you do not need to set this to an estimate of the number of rows in the file for better speed because that is already automatically determined by \code{fread} almost instantly using the large sample of lines. \code{nrows=0} returns the column names and typed empty columns determined by the large sample; useful for a dry run of a large file or to quickly check format consistency of a set of files before starting to read any of them. } \item{\code{header}}{ Does the first data line contain column names? Defaults according to whether every non-empty field on the first data line is type character. If so, or TRUE is supplied, any empty column names are given a default name. } \item{\code{na.strings}}{ A character vector of strings which are to be interpreted as \code{NA} values. By default, \code{",,"} for columns of all types, including type \code{character} is read as \code{NA} for consistency. \code{,"",} is unambiguous and read as an empty string. To read \code{,NA,} as \code{NA}, set \code{na.strings="NA"}. To read \code{,,} as blank string \code{""}, set \code{na.strings=NULL}. When they occur in the file, the strings in \code{na.strings} should not appear quoted since that is how the string literal \code{,"NA",} is distinguished from \code{,NA,}, for example, when \code{na.strings="NA"}. } - \item{\code{stringsAsFactors}}{ Convert all or some character columns to factors? Acceptable inputs are \code{TRUE}, \code{FALSE}, or a decimal value between 0.0 and 1.0. For \code{stringsAsFactors = FALSE}, all string columns are stored as \code{character} vs. all stored as \code{factor} when \code{TRUE}. When \code{stringsAsFactors = p} for \code{0 <= p <= 1}, string columns \code{col} are stored as \code{factor} if \code{uniqueN(col)/nrow < p}. - } + \item{\code{stringsAsFactors}}{ Convert all character columns to factors? } \item{\code{verbose}}{ Be chatty and report timings? } \item{\code{skip}}{ If 0 (default) start on the first line and from there finds the first row with a consistent number of columns. This automatically avoids irregular header information before the column names row. \code{skip>0} means ignore the first \code{skip} rows manually. \code{skip="string"} searches for \code{"string"} in the file (e.g. a substring of the column names row) and starts on that line (inspired by read.xls in package gdata). } \item{\code{select}}{ A vector of column names or numbers to keep, drop the rest. \code{select} may specify types too in the same way as \code{colClasses}; i.e., a vector of \code{colname=type} pairs, or a \code{list} of \code{type=col(s)} pairs. In all forms of \code{select}, the order that the columns are specified determines the order of the columns in the result. } diff --git a/man/dictionary_player_stats_def.Rd b/man/dictionary_player_stats_def.Rd new file mode 100644 index 00000000..54c0d3f4 --- /dev/null +++ b/man/dictionary_player_stats_def.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{dictionary_player_stats_def} +\alias{dictionary_player_stats_def} +\title{Data Dictionary: Player Stats Defense} +\format{ +An object of class \code{data.frame} with 22 rows and 3 columns. +} +\usage{ +dictionary_player_stats_def +} +\description{ +A dataframe containing the data dictionary for \code{\link[=load_player_stats]{load_player_stats()}} +} +\seealso{ +\code{vignette("Data Dictionary - Player Stats Defense")} + +\url{https://nflreadr.nflverse.com/articles/dictionary_player_stats_def.html} +} +\keyword{datasets} diff --git a/vignettes/dictionary_player_stats_def.Rmd b/vignettes/dictionary_player_stats_def.Rmd new file mode 100644 index 00000000..65b92f85 --- /dev/null +++ b/vignettes/dictionary_player_stats_def.Rmd @@ -0,0 +1,29 @@ +--- +title: "Data Dictionary - Player Stats Defense" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Data Dictionary - Player Stats Defense} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + echo = FALSE, + comment = "#>" +) +use_dt <- FALSE +if(requireNamespace("DT", quietly = TRUE)) use_dt <- TRUE +``` + +```{r eval = use_dt} +DT::datatable(nflreadr::dictionary_player_stats_def, + options = list(scrollX = TRUE, pageLength = 25), + filter = "top", + rownames = FALSE + ) +``` + +```{r eval = !use_dt} +knitr::kable(nflreadr::dictionary_player_stats_def) +```