Title: | Download 'nflverse' Data |
Version: | 1.4.1 |
Description: | A minimal package for downloading data from 'GitHub' repositories of the 'nflverse' project. |
License: | MIT + file LICENSE |
URL: | https://nflreadr.nflverse.com, https://github.com/nflverse/nflreadr |
BugReports: | https://github.com/nflverse/nflreadr/issues |
Depends: | R (≥ 3.6.0) |
Imports: | cachem (≥ 1.0.0), cli (≥ 3.0.0), curl (≥ 4.3.0), data.table (≥ 1.14.0), glue (≥ 1.4.0), memoise (≥ 2.0.0), methods, rappdirs (≥ 0.3.0), rlang (≥ 0.4.10), tools, utils |
Suggests: | arrow (≥ 6.0.0), covr (≥ 3.0.0), DT (≥ 0.15.0), fs (≥ 1.5.0), gh (≥ 1.0.0), knitr (≥ 1.0.0), piggyback (≥ 0.1.2), progressr (≥ 0.8.0), qs (≥ 0.24.0), rmarkdown (≥ 2.6.0), stringi, testthat (≥ 3.0.0) |
VignetteBuilder: | knitr |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.2.3 |
NeedsCompilation: | no |
Packaged: | 2024-07-29 00:49:39 UTC; tan |
Author: | Tan Ho |
Maintainer: | Tan Ho <tan@tanho.ca> |
Repository: | CRAN |
Date/Publication: | 2024-07-29 13:10:02 UTC |
nflreadr: Download 'nflverse' Data
Description
A minimal package for downloading data from 'GitHub' repositories of the 'nflverse' project.
Author(s)
Maintainer: Tan Ho tan@tanho.ca (ORCID) [copyright holder]
Authors:
Sebastian Carl mrcaseb@gmail.com
Other contributors:
John Edwards edwards1860@gmail.com [contributor]
Ben Baldwin bbaldwin206@gmail.com [contributor]
Thomas Mock [contributor]
Lee Sharpe [contributor]
Pranav Rajaram pranavrajaram@gmail.com [contributor]
See Also
Useful links:
Report bugs at https://github.com/nflverse/nflreadr/issues
CRAN setup code
Description
Some code to comply with CRAN policies, e.g. limiting data.table CPU cores for examples/tests
Usage
.for_cran()
Show dependency versions of installed packages
Description
Show dependency versions of installed packages
Usage
.sitrep_pkg_deps(
packages,
inst_pkgs = utils::installed.packages(),
recursive = TRUE
)
Show options for installed packages
Description
Show options for installed packages
Usage
.sitrep_pkg_opts(packages, redact_path = TRUE)
Clean Home/Away in dataframes into Team/Opponent dataframes
Description
This function converts dataframes with "home_" and "away_" prefixed columns to "team_" and "opponent_", and doubles the rows. This makes sure that there's one row for each team (as opposed to one row for each game).
Usage
clean_homeaway(dataframe, invert = NULL)
Arguments
dataframe |
dataframe |
invert |
a character vector of columns that gets inverted when referring to the away team (e.g. home spread = 1 gets converted to away_spread = -1) |
Value
a dataframe with one row per team (twice as long as the input dataframe)
Examples
# a small example dataframe
s <- data.frame(
game_id = c("2020_20_TB_GB", "2020_20_BUF_KC", "2020_21_KC_TB"),
game_type = c("CON", "CON", "SB"),
away_team = c("TB", "BUF", "KC"),
away_score = c(31L, 24L, 9L),
home_team = c("GB", "KC", "TB"),
home_score = c(26L, 38L, 31L),
location = c("Home", "Home", "Neutral"),
result = c(-5L, 14L, 22L),
spread_line = c(3, 3, -3)
)
clean_homeaway(s, invert = c("result","spread_line"))
Create Player Merge Names
Description
Applies some name-cleaning heuristics to facilitate joins. These heuristics may include:
removing periods and apostrophes
removing common suffixes, such as Jr, Sr, II, III, IV
converting to lowercase
using
ffscrapr::dp_name_mapping
to do common name substitutions, such as Mitch Trubisky to Mitchell Trubisky
Usage
clean_player_names(
player_name,
lowercase = FALSE,
convert_lastfirst = TRUE,
use_name_database = TRUE,
convert_to_ascii = rlang::is_installed("stringi")
)
Arguments
player_name |
a character vector of player names |
lowercase |
defaults to FALSE - if TRUE, converts to lowercase |
convert_lastfirst |
defaults to TRUE - converts names from "Last, First" to "First Last" |
use_name_database |
uses internal name database to do common substitutions (Mitchell Trubisky to Mitch Trubisky etc) |
convert_to_ascii |
If |
Details
Equivalent to the operation done by ffscrapr::dp_clean_names()
and uses the same player name database.
Value
a character vector of cleaned names
Examples
clean_player_names(c("A.J. Green", "Odell Beckham Jr. ", "Le'Veon Bell Sr."))
clean_player_names(c("Trubisky, Mitch", "Atwell, Chatarius", "Elliott, Zeke", "Elijah Moore"),
convert_lastfirst = TRUE)
Standardize NFL Team Abbreviations
Description
This function standardizes NFL team abbreviations to nflverse defaults. This helps for joins and plotting, especially with the new nflplotR package!
Usage
clean_team_abbrs(abbr, current_location = TRUE, keep_non_matches = TRUE)
Arguments
abbr |
a character vector of abbreviations |
current_location |
If |
keep_non_matches |
If |
Value
A character vector with the length of abbr
and cleaned team abbreviations
if they are included in team_abbr_mapping
or team_abbr_mapping_norelocate
(depending on the value of current_location
). Non matches may be replaced
with NA
(depending on the value of keep_non_matches
).
Examples
x <- c("PIE", "LAR", "PIT", "CRD", "OAK", "SL")
# use current location and keep non matches
clean_team_abbrs(x)
# keep old location and replace non matches
clean_team_abbrs(x, current_location = FALSE, keep_non_matches = FALSE)
Clear function cache
Description
This function clears the memoised cache of all functions memoised by nflreadr
.
Usage
clear_cache()
.clear_cache()
Value
A success message after clearing the cache.
Examples
clear_cache()
Load .csv / .csv.gz file from a remote connection
Description
This is a thin wrapper on data.table::fread, but memoised & cached for twenty four hours.
Usage
csv_from_url(...)
Arguments
... |
Arguments passed on to
|
Value
a dataframe as created by data.table::fread()
Examples
try({ # prevents cran errors
csv_from_url("https://github.com/nflverse/nflverse-data/releases/download/test/combines.csv")
})
Data Dictionary: Combine
Description
A dataframe containing the data dictionary for load_combine()
Usage
dictionary_combine
Format
An object of class data.frame
with 18 rows and 3 columns.
See Also
vignette("Data Dictionary - Combine")
https://nflreadr.nflverse.com/articles/dictionary_combine.html
Data Dictionary: Contracts
Description
A dataframe containing the data dictionary for load_contracts()
Usage
dictionary_contracts
Format
An object of class data.frame
with 15 rows and 3 columns.
See Also
vignette("Data Dictionary - Contracts")
https://nflreadr.nflverse.com/articles/dictionary_contracts.html
Data Dictionary: Depth Charts
Description
A dataframe containing the data dictionary for load_depth_charts()
Usage
dictionary_depth_charts
Format
An object of class data.frame
with 13 rows and 3 columns.
See Also
vignette("Data Dictionary - Depth Charts")
https://nflreadr.nflverse.com/articles/dictionary_depth_charts.html
Data Dictionary: Draft Picks
Description
A dataframe containing the data dictionary for load_draft_picks()
Usage
dictionary_draft_picks
Format
An object of class data.frame
with 36 rows and 3 columns.
See Also
vignette("Data Dictionary - Draft Picks")
https://nflreadr.nflverse.com/articles/dictionary_draft_picks.html
Data Dictionary: ESPN QBR
Description
A dataframe containing the data dictionary for load_espn_qbr()
Usage
dictionary_espn_qbr
Format
An object of class data.frame
with 23 rows and 3 columns.
See Also
vignette("Data Dictionary - ESPN QBR")
https://nflreadr.nflverse.com/articles/dictionary_espn_qbr.html
Data Dictionary: Expected Fantasy Points
Description
A dataframe containing the data dictionary for load_ff_opportunity()
Usage
dictionary_ff_opportunity
Format
An object of class data.frame
with 218 rows and 4 columns.
See Also
vignette("Data Dictionary - Expected Fantasy Points")
https://nflreadr.nflverse.com/articles/dictionary_ff_opportunity.html
Data Dictionary: Fantasy Player IDs
Description
A dataframe containing the data dictionary for load_ff_playerids()
Usage
dictionary_ff_playerids
Format
An object of class data.frame
with 35 rows and 3 columns.
See Also
vignette("Data Dictionary - FF Player IDs")
https://nflreadr.nflverse.com/articles/dictionary_ff_playerids.html
Data Dictionary: Fantasy Football Rankings
Description
A dataframe containing the data dictionary for load_ff_rankings()
Usage
dictionary_ff_rankings
Format
An object of class data.frame
with 25 rows and 3 columns.
See Also
vignette("Data Dictionary - FF Rankings")
https://nflreadr.nflverse.com/articles/dictionary_ff_rankings.html
Data Dictionary: FTN Charting Data
Description
A dataframe containing the data dictionary for load_ftn_charting()
Usage
dictionary_ftn_charting
Format
An object of class data.frame
with 28 rows and 5 columns.
See Also
vignette("Data Dictionary - FTN Charting")
https://nflreadr.nflverse.com/articles/dictionary_ftn_charting.html
Other ftn_charting:
load_ftn_charting()
Data Dictionary: Injuries
Description
A dataframe containing the data dictionary for load_injuries()
Usage
dictionary_injuries
Format
An object of class data.frame
with 16 rows and 3 columns.
See Also
vignette("Data Dictionary - Injuries")
https://nflreadr.nflverse.com/articles/dictionary_injuries.html
Data Dictionary: Next Gen Stats
Description
A dataframe containing the data dictionary for load_nextgen_stats()
Usage
dictionary_nextgen_stats
Format
An object of class data.frame
with 51 rows and 3 columns.
See Also
vignette("Data Dictionary - Next Gen Stats")
https://nflreadr.nflverse.com/articles/dictionary_nextgen_stats.html
Data Dictionary: Participation
Description
A dataframe containing the data dictionary for load_participation()
Usage
dictionary_participation
Format
An object of class data.frame
with 19 rows and 3 columns.
See Also
vignette("Data Dictionary - Participation")
https://nflreadr.nflverse.com/articles/dictionary_participation.html
Data Dictionary: Play by Play
Description
A dataframe containing the data dictionary for load_pbp()
Usage
dictionary_pbp
Format
An object of class data.frame
with 372 rows and 3 columns.
See Also
vignette("Data Dictionary - PBP")
https://nflreadr.nflverse.com/articles/dictionary_pbp.html
Data Dictionary: PFR Passing
Description
A dataframe containing the data dictionary for load_pfr_passing()
Usage
dictionary_pfr_passing
Format
An object of class data.frame
with 28 rows and 3 columns.
See Also
https://nflreadr.nflverse.com/articles/dictionary_pfr_passing.html
vignette("Data Dictionary - PFR Passing")
Data Dictionary: Player Stats
Description
A dataframe containing the data dictionary for load_player_stats()
Usage
dictionary_player_stats
Format
An object of class data.frame
with 48 rows and 2 columns.
See Also
vignette("Data Dictionary - Player Stats")
https://nflreadr.nflverse.com/articles/dictionary_player_stats.html
Data Dictionary: Player Stats Defense
Description
A dataframe containing the data dictionary for load_player_stats()
Usage
dictionary_player_stats_def
Format
An object of class data.frame
with 22 rows and 3 columns.
See Also
vignette("Data Dictionary - Player Stats Defense")
https://nflreadr.nflverse.com/articles/dictionary_player_stats_def.html
Data Dictionary: Rosters
Description
A dataframe containing the data dictionary for load_rosters()
Usage
dictionary_rosters
Format
An object of class data.frame
with 25 rows and 3 columns.
See Also
vignette("Data Dictionary - Rosters")
https://nflreadr.nflverse.com/articles/dictionary_rosters.html
Data Dictionary: Schedules
Description
A dataframe containing the data dictionary for load_schedules()
Usage
dictionary_schedules
Format
An object of class data.frame
with 45 rows and 3 columns.
See Also
vignette("Data Dictionary - Schedules")
https://nflreadr.nflverse.com/articles/dictionary_schedules.html
Data Dictionary: Snap Counts
Description
A dataframe containing the data dictionary for load_snap_counts()
Usage
dictionary_snap_counts
Format
An object of class data.frame
with 16 rows and 3 columns.
See Also
vignette("Data Dictionary - Snap Counts")
https://nflreadr.nflverse.com/articles/dictionary_snap_counts.html
Data Dictionary: Trades
Description
A dataframe containing the data dictionary for load_trades()
Usage
dictionary_trades
Format
An object of class data.frame
with 11 rows and 3 columns.
See Also
vignette("Data Dictionary - Trades")
https://nflreadr.nflverse.com/articles/dictionary_trades.html
Get Current Week
Description
A helper function that returns the upcoming NFL regular season week based on either
the nflverse schedules file (as found in load_schedules()
)
or some date-based heuristics (number of weeks since the first Monday of September)
Usage
get_current_week(use_date = FALSE)
Arguments
use_date |
a logical to determine whether to use date-based heuristics to determine current week, default FALSE (i.e. uses schedule file) |
Details
Note that the date heuristic will count a new week starting on Thursdays, while the schedule-based method will count a new week after the last game of the previous week, e.g. after MNF is completed. Tan and Ben argued for a while about this.
Value
current nfl regular season week as a numeric
See Also
Other Date utils:
most_recent_season()
Examples
{
try({ # schedules file as per default requires online access
get_current_week()
})
# using the date method works offline
get_current_week(use_date = TRUE)
}
Coalescing join
Description
EXPERIMENTAL! This function joins two dataframes together by key, and then coalesces any columns that have shared names (i.e. fills in NAs). A utility function primarily used internally within nflverse to help build player IDs
Usage
join_coalesce(
x,
y,
by = NULL,
type = c("left", "inner", "full"),
...,
by.x = NULL,
by.y = NULL,
sort = TRUE,
incomparables = c(NA, NaN)
)
Arguments
x , y |
dataframes. Will be coerced to data.table |
by |
keys to join on, as a plain or named character vector |
type |
one of "left" (all rows of x and matching rows of y), "inner" (matching rows of x and y), "full" (all rows of x and y) |
... |
other args passed to |
by.x , by.y |
alternate form of keys to join on - if provided, will override |
sort |
whether to sort output by the join keys |
incomparables |
keys to NOT match on, i.e. NA should not match on NA. |
Value
a data.frame joining x and y dataframes together, with every column from both x and y and patching NA values in x with those in y.
Examples
x <- data.frame(id1 = c(NA_character_,letters[1:4]), a = c(1,NA,3,NA,5), b = 1:5 * 10)
y <- data.frame(id2 = c(letters[3:11],NA_character_), a = -(1:10), c = 1:10 * 100)
join_coalesce(x,y, by = c("id1"="id2"))
join_coalesce(x,y, by.x = "id1", by.y = "id2")
join_coalesce(x,y, by = c("id1"="id2"), type = "inner")
join_coalesce(x,y, by = c("id1"="id2"), type = "full")
Load Combine Data from PFR
Description
Loads combine data since 2000 courtesy of PFR.
Usage
load_combine(
seasons = TRUE,
file_type = getOption("nflreadr.prefer", default = "rds")
)
Arguments
seasons |
a numeric vector of seasons to return, default |
file_type |
One of |
Value
A tibble of NFL combine data provided by Pro Football Reference.
See Also
Issues with this data should be filed here: https://github.com/nflverse/nflverse-data
https://nflreadr.nflverse.com/articles/dictionary_combine.html for a web version of the dictionary
dictionary_combine
for the data dictionary as bundled within the package
Examples
try({ # prevents cran errors
load_combine()
})
Load Historical Player Contracts from OverTheCap.com
Description
Loads player contracts from OverTheCap.com
Usage
load_contracts(file_type = getOption("nflreadr.prefer", default = "rds"))
Arguments
file_type |
One of |
Value
A tibble of active and non-active NFL player contracts.
See Also
https://overthecap.com/contract-history for a web version of the data
https://nflreadr.nflverse.com/articles/dictionary_contracts.html for a web version of the dictionary
dictionary_contracts
for the data dictionary as bundled within the package
Issues with this data should be filed here: https://github.com/nflverse/rotc
Examples
try({ # prevents cran errors
load_contracts()
})
Load Weekly Depth Charts
Description
Loads depth charts for each NFL team for each week back to 2001.
Usage
load_depth_charts(
seasons = most_recent_season(),
file_type = getOption("nflreadr.prefer", default = "rds")
)
Arguments
seasons |
a numeric vector specifying what seasons to return, if |
file_type |
One of |
Value
A tibble of week-level depth charts for each team.
See Also
https://nflreadr.nflverse.com/articles/dictionary_depth_charts.html for a web version of the dictionary
dictionary_depth_charts
for the data dictionary as bundled within the package
Issues with this data should be filed here: https://github.com/nflverse/nflverse-data
Examples
try({ # prevents cran errors
load_depth_charts(2020)
})
Load Draft Picks from PFR
Description
Loads every draft pick since 1980 courtesy of PFR.
Usage
load_draft_picks(
seasons = TRUE,
file_type = getOption("nflreadr.prefer", default = "rds")
)
Arguments
seasons |
a numeric vector of seasons to return, default |
file_type |
One of |
Value
A tibble of NFL draft picks provided by Pro Football Reference.
See Also
https://nflreadr.nflverse.com/articles/dictionary_draft_picks.html for the web data dictionary
dictionary_draft_picks
for the data dictionary as bundled within the package
Issues with this data should be filed here: https://github.com/nflverse/nflverse-data
Examples
try({ # prevents cran errors
load_draft_picks()
})
Load ESPN's QBR
Description
Load ESPN's QBR
Usage
load_espn_qbr(
seasons = most_recent_season(),
summary_type = c("season", "week"),
file_type = getOption("nflreadr.prefer", default = "rds")
)
Arguments
seasons |
a numeric vector of seasons to return, data available since 2006. Defaults to latest season available. TRUE will select all seasons. |
summary_type |
One of |
file_type |
One of |
Value
a tibble of ESPN QBR data, summarized according to summary_type
See Also
https://nflreadr.nflverse.com/articles/dictionary_espn_qbr.html for a web version of the dictionary
dictionary_espn_qbr
for the data dictionary as bundled within the package
Issues with this data should be filed here: https://github.com/nflverse/espnscrapeR-data
Examples
load_espn_qbr(2020)
Load Expected Fantasy Points
Description
This function downloads precomputed expected points data from ffopportunity automated releases.
Usage
load_ff_opportunity(
seasons = most_recent_season(),
stat_type = c("weekly", "pbp_pass", "pbp_rush"),
model_version = c("latest", "v1.0.0")
)
Arguments
seasons |
a numeric vector of seasons to return, defaults to most recent season. If set to |
stat_type |
one of |
model_version |
one of |
Value
Precomputed expected fantasy points data from the ffopportunity automated releases.
See Also
https://ffopportunity.ffverse.com for more on the package, data, and modelling
https://nflreadr.nflverse.com/articles/dictionary_ff_opportunity.html for the web data dictionary
dictionary_ff_opportunity
for the data dictionary bundled as a package data frame
Issues with this data should be filed here: https://github.com/ffverse/ffopportunity
Examples
try({ # prevents cran errors
load_ff_opportunity()
load_ff_opportunity(seasons = 2021, stat_type = "pbp_pass", model_version = "v1.0.0")
})
Load Fantasy Player IDs
Description
Accesses DynastyProcess.com's database of fantasy football player IDs, which help connect nflverse to various other platforms and IDs.
Usage
load_ff_playerids()
Value
a dataframe of player IDs
See Also
https://nflreadr.nflverse.com/articles/dictionary_ff_playerids.html for the web data dictionary
Issues with this data should be filed here: https://github.com/dynastyprocess/data
Examples
try({ # prevents cran errors
load_ff_playerids()
})
Load Latest FantasyPros Rankings
Description
Accesses DynastyProcess.com's repository of the latest FP expert consensus rankings - updated on a weekly basis.
Usage
load_ff_rankings(type = c("draft", "week", "all"))
Arguments
type |
one of "draft" (preseason), "week" (this week, inseason), or "all" (full archive) |
Value
a dataframe of expert consensus rankings
See Also
https://nflreadr.nflverse.com/articles/dictionary_ff_rankings.html for the web data dictionary
https://www.fantasypros.com for the source of data
Issues with this data should be filed here: https://github.com/dynastyprocess/data
Examples
try({ # prevents cran errors
load_ff_rankings()
})
Load any rds/csv/csv.gz/parquet/qs file from a remote URL
Description
Load any rds/csv/csv.gz/parquet/qs file from a remote URL
Usage
load_from_url(url, ..., seasons = TRUE, nflverse = FALSE)
Arguments
url |
a vector of URLs to load into memory. If more than one URL provided, will row-bind them. |
... |
named arguments that will be added as attributes to the data, e.g. |
seasons |
a numeric vector of years that will be used to filter the dataframe's |
nflverse |
TRUE to add nflverse_data classing and attributes. |
Value
a dataframe, possibly of type nflverse_data
Examples
try({ # prevents cran errors
urls <- c("https://github.com/nflverse/nflverse-data/releases/download/rosters/roster_2020.csv",
"https://github.com/nflverse/nflverse-data/releases/download/rosters/roster_2021.csv")
load_from_url(urls, nflverse = TRUE, nflverse_type = "rosters for 2020 & 2021")
})
Load FTN Charting Data
Description
FTN Data manually charts plays and has graciously provided a subset of their charting data to be published via the nflverse. Data is available from the 2022 season onwards and is charted within 48 hours following each game. This data is released under the CC-BY-SA 4.0 Creative Commons license and attribution must be made to FTN Data via nflverse
Usage
load_ftn_charting(
seasons = most_recent_season(),
file_type = getOption("nflreadr.prefer", default = "rds")
)
Arguments
seasons |
a numeric vector of seasons to return, defaults to most recent season.
If set to |
file_type |
One of |
Value
Play-level manual charting data from FTN Data
Author(s)
FTN Data
Source
FTNData.com
See Also
vignette("Data Dictionary - FTN Charting")
https://nflreadr.nflverse.com/articles/dictionary_ftn_charting.html for the web data dictionary
Other ftn_charting:
dictionary_ftn_charting
Examples
try({ # prevents cran errors
load_ftn_charting()
})
Load Injury Reports
Description
Data collected from an API for weekly injury report data.
Usage
load_injuries(
seasons = most_recent_season(),
file_type = getOption("nflreadr.prefer", default = "rds")
)
Arguments
seasons |
a numeric vector of seasons to return, data available since 2009. Defaults to latest season available. |
file_type |
One of |
Value
a tibble of season-level injury report data.
See Also
https://nflreadr.nflverse.com/articles/dictionary_injuries.html for a web version of the dictionary
dictionary_injuries
for the data dictionary as bundled within the package
Issues with this data should be filed here: https://github.com/nflverse/nflverse-data
Examples
try({# prevents cran errors
load_injuries(2020)
})
Load Player Level Weekly NFL Next Gen Stats
Description
Loads player level weekly stats provided by NFL Next Gen Stats starting with the 2016 season. Three different stat types are available and the current season's data updates every night. NGS will only provide data for players above a minimum number of pass/rush/rec attempts.
Usage
load_nextgen_stats(
seasons = TRUE,
stat_type = c("passing", "receiving", "rushing"),
file_type = getOption("nflreadr.prefer", default = "rds")
)
Arguments
seasons |
a numeric vector specifying what seasons to return, if |
stat_type |
one of |
file_type |
One of |
Value
A tibble of week-level player statistics provided by NFL Next Gen Stats.
Regular season summary is given for week == 0
.
See Also
https://nextgenstats.nfl.com/stats/passing for stat_type = "passing"
https://nextgenstats.nfl.com/stats/receiving for stat_type = "receiving"
https://nextgenstats.nfl.com/stats/rushing for stat_type = "rushing"
https://nflreadr.nflverse.com/articles/dictionary_nextgen_stats.html for a web version of the data dictionary
dictionary_nextgen_stats
for the data dictionary as bundled within the package
Issues with this data should be filed here: https://github.com/nflverse/nflverse-data
Examples
try({ # prevents cran errors
load_nextgen_stats(stat_type = "passing")
load_nextgen_stats(stat_type = "receiving")
load_nextgen_stats(stat_type = "rushing")
})
Load Officials
Description
Loads data on which officials are assigned to oversee a specific game. Data available from 2015 onwards.
Usage
load_officials(
seasons = TRUE,
file_type = getOption("nflreadr.prefer", default = "rds")
)
Arguments
seasons |
a numeric vector specifying what seasons to return, if |
file_type |
One of |
Value
A tibble with one row per game per official.
See Also
Issues with this data should be filed here: https://github.com/nflverse/nflreadr and it will be triaged appropriately.
Examples
try({ # prevents cran errors
load_officials()
})
Load Participation Data
Description
Loads participation data from the nflverse-data repository
Usage
load_participation(
seasons = most_recent_season(),
include_pbp = FALSE,
file_type = getOption("nflreadr.prefer", default = "rds")
)
Arguments
seasons |
A numeric vector of 4-digit years associated with given NFL seasons - defaults to latest season. If set to |
include_pbp |
a logical: download and join pbp to this data? |
file_type |
One of |
Value
A dataframe of participation data, optionally merged with play by play
Examples
try({ # prevents cran errors
load_participation(seasons = 2020, include_pbp = TRUE)
})
Load Play By Play
Description
Loads play by play seasons from the nflverse-data repository
Usage
load_pbp(
seasons = most_recent_season(),
file_type = getOption("nflreadr.prefer", default = "rds")
)
Arguments
seasons |
A numeric vector of 4-digit years associated with given NFL seasons - defaults to latest season. If set to |
file_type |
One of |
Value
The complete nflfastR dataset as returned by nflfastR::build_nflfastR_pbp()
(see below) for all given seasons
See Also
https://nflreadr.nflverse.com/articles/dictionary_pbp.html for a web version of the data dictionary
dictionary_pbp
for the data dictionary bundled as a package dataframe
https://www.nflfastr.com/reference/build_nflfastR_pbp.html for the nflfastR function nflfastR::build_nflfastR_pbp()
Issues with this data should be filed here: https://github.com/nflverse/nflverse-pbp
Examples
try({ # prevents cran errors
load_pbp(2019:2020)
})
Load Advanced Stats from PFR
Description
Loads player level season stats provided by Pro Football Reference starting with the 2018 season, primarily to augment existing nflverse data.
Usage
load_pfr_advstats(
seasons = most_recent_season(),
stat_type = c("pass", "rush", "rec", "def"),
summary_level = c("week", "season"),
file_type = getOption("nflreadr.prefer", default = "rds")
)
Arguments
seasons |
a numeric vector specifying what seasons to return, if |
stat_type |
one of "pass", "rush", "rec", "def" |
summary_level |
one of "week" (default) or "season" - some data is only available at the season level |
file_type |
One of |
Value
A tibble of player statistics provided by Pro Football Reference that supplements data in nflverse
See Also
https://nflreadr.nflverse.com/articles/dictionary_pfr_passing.html for the web data dictionary
https://www.pro-football-reference.com/years/2021/passing_advanced.htm
Issues with this data should be filed here: https://github.com/nflverse/nflverse-data
Examples
try({ # prevents cran errors
load_pfr_advstats()
})
Load Advanced Passing Stats from PFR
Description
Loads player level season stats provided by Pro Football Reference starting with the 2019 season.
Usage
load_pfr_passing(seasons = TRUE)
Arguments
seasons |
a numeric vector specifying what seasons to return, if |
Value
A tibble of season-level player statistics provided by Pro Football Reference.
See Also
https://nflreadr.nflverse.com/articles/dictionary_pfr_passing.html for the web data dictionary
dictionary_pfr_passing
for the data dictionary as bundled within the package
Issues with this data should be filed here: https://github.com/nflverse/nflverse-pfr
Examples
load_pfr_passing()
Load Player Level Weekly Stats
Description
Load Player Level Weekly Stats
Usage
load_player_stats(
seasons = most_recent_season(),
stat_type = c("offense", "defense", "kicking"),
file_type = getOption("nflreadr.prefer", default = "rds")
)
Arguments
seasons |
a numeric vector of seasons to return, defaults to most recent season. If set to |
stat_type |
one of |
file_type |
One of |
Value
A tibble of week-level player statistics that aims to match NFL official box scores.
See Also
https://nflreadr.nflverse.com/articles/dictionary_player_stats.html for a web version of the data dictionary
dictionary_player_stats
for the data dictionary
Issues with this data should be filed here: https://github.com/nflverse/nflverse-pbp
Examples
try({ # prevents cran errors
load_player_stats()
load_player_stats(stat_type = "kicking")
})
Load Players
Description
Load a dataframe of player-level information, including IDs and other mostly-immutable data (birthdates, college, draft position etc.)
Usage
load_players(file_type = getOption("nflreadr.prefer", default = "rds"))
Arguments
file_type |
One of |
Value
A tibble with one row per player.
See Also
Issues with this data should be filed here: https://github.com/nflverse/nflreadr and it will be triaged appropriately.
Examples
try({ # prevents cran errors
load_players()
})
Load Rosters
Description
Load Rosters
Usage
load_rosters(
seasons = most_recent_season(roster = TRUE),
file_type = getOption("nflreadr.prefer", default = "rds")
)
Arguments
seasons |
a numeric vector of seasons to return, defaults to returning
this year's data if it is March or later. If set to |
file_type |
One of |
Value
A tibble of season-level roster data.
See Also
https://nflreadr.nflverse.com/articles/dictionary_rosters.html for a web version of the data dictionary
dictionary_rosters
for the data dictionary as a dataframe
Issues with this data should be filed here: https://github.com/nflverse/nflverse-data
Examples
try({ # prevents cran errors
load_rosters(2020)
})
Load Weekly Rosters
Description
Returns week level rosters (rather than latest for a given season as returned by load_rosters()
)
Usage
load_rosters_weekly(
seasons = most_recent_season(roster = TRUE),
file_type = getOption("nflreadr.prefer", default = "rds")
)
Arguments
seasons |
a numeric vector of seasons to return, defaults to returning
this year's data if it is March or later. If set to |
file_type |
One of |
Value
A tibble of weekly roster data.
See Also
Issues with this data should be filed here: https://github.com/nflverse/nflverse-data
Examples
try({ # prevents cran errors
load_rosters_weekly(2020)
})
Load Game/Schedule Data
Description
This returns game/schedule information as maintained by Lee Sharpe.
Usage
load_schedules(seasons = TRUE)
Arguments
seasons |
a numeric vector of seasons to return, default |
Value
A tibble of game information for past and/or future games.
See Also
https://nflreadr.nflverse.com/articles/dictionary_schedules.html for a web version of the data dictionary
dictionary_schedules
for the data dictionary as a dataframe
Issues with this data should be filed here: https://github.com/nflverse/nfldata
Examples
try({ # prevents cran errors
load_schedules(2020)
})
Load Snap Counts from PFR
Description
Loads game level snap counts stats provided by Pro Football Reference starting with the 2012 season.
Usage
load_snap_counts(
seasons = most_recent_season(),
file_type = getOption("nflreadr.prefer", default = "rds")
)
Arguments
seasons |
a numeric vector specifying what seasons to return, if |
file_type |
One of |
Value
A tibble of game-level snap counts provided by Pro Football Reference.
See Also
https://nflreadr.nflverse.com/articles/dictionary_snap_counts.html for the web data dictionary
dictionary_snap_counts
for the data dictionary as bundled within the package
Issues with this data should be filed here: https://github.com/nflverse/nflverse-pfr
Examples
try({ # prevents CRAN errors
load_snap_counts()
})
Load NFL Team Graphics, Colors, and Logos
Description
Loads team graphics, colors, and logos - useful for plots!
Usage
load_teams(current = TRUE)
Arguments
current |
If |
Value
A tibble of team-level image URLs and hex color codes.
See Also
Issues with this data should be filed here: https://github.com/nflverse/nflverse-pbp
Examples
try({ # prevents cran errors
load_teams()
})
Load Trades
Description
This returns a table of historical trades as maintained by Lee Sharpe.
Usage
load_trades(seasons = TRUE)
Arguments
seasons |
a numeric vector of seasons to return, default |
Value
A tibble of game information for past and/or future games.
See Also
https://nflreadr.nflverse.com/articles/dictionary_trades.html for a web version of the dictionary
dictionary_trades
for the data dictionary as bundled within the package
Issues with this data should be filed here: https://github.com/nflverse/nfldata
Examples
load_trades(2020)
Get Latest Season
Description
A helper function to choose the most recent season available for a given dataset
Usage
most_recent_season(roster = FALSE)
get_latest_season(roster = FALSE)
get_current_season(roster = FALSE)
Arguments
roster |
Either |
Value
most recent season (a four digit numeric)
See Also
Other Date utils:
get_current_week()
nflverse data class
Description
This class has a special S3 print method that tries to read attached metadata and
provide timestamps and source attributes. It otherwise will dispatch to the
data.frame
class.
Usage
as.nflverse_data(df, nflverse_type = NULL, ...)
Bulk download utilities via piggyback
Description
This function downloads or updates data from the nflverse-data repository releases, creating subfolders that match the release structure.
Usage
nflverse_download(
...,
folder_path = getOption("nflreadr.download_path", default = "."),
file_type = getOption("nflreadr.prefer", default = "rds"),
use_hive = file_type %in% c("parquet", "csv"),
.token = "default"
)
Arguments
... |
releases to download, provided in either unquoted or character format
(i.e. pbp or "pbp" are both fine). Available release names can be listed with
|
folder_path |
a folder in which subfolders will be created for each release -
defaults to path specified in |
file_type |
one of |
use_hive |
whether to create hive-style partition folders for each season, e.g. |
.token |
a GitHub API token, |
Examples
try({
## could also set options like
# options(nflreadr.download_path = tempdir(), nflreadr.prefer = "parquet")
nflverse_download(combine, contracts, folder_path = tempdir(), file_type = "parquet")
list.files(tempdir(),pattern = ".parquet$") # check that files were downloaded!
})
Compute nflverse Game Identifiers
Description
Compute nflverse Game Identifiers
Usage
nflverse_game_id(season, week, away, home)
Arguments
season |
4 digit season between 1999 and the output of |
week |
Numeric or character giving the week, between 1 and 22. |
home , away |
Valid NFL team abbreviation as it can be found in team_abbr_mapping |
Value
A character vector
Examples
nflverse_game_id(2022, 2, "LAC", "KC")
List all available nflverse releases
Description
This functions lists all nflverse data releases that are available
in the nflverse-data repo. Release names can be used for downloads in
nflverse_download()
.
Usage
nflverse_releases(.token = "default")
Arguments
.token |
a GitHub API token, |
Value
A dataframe containing release names, release descriptions, and other relevant release information.
Examples
try( # avoids cran failures, can skip in normal usage
nflverse_releases()
)
Get a Situation Report on System, nflverse/ffverse Package Versions and Dependencies
Description
This function gives a quick overview of the versions of R and the operating system as well as the versions of nflverse/ffverse packages, options, and their dependencies. It's primarily designed to help you get a quick idea of what's going on when you're helping someone else debug a problem.
Usage
nflverse_sitrep(
pkg = c("nflreadr", "nflfastR", "nflseedR", "nfl4th", "nflplotR", "nflverse"),
recursive = TRUE,
redact_path = TRUE
)
ffverse_sitrep(
pkg = c("ffscrapr", "ffsimulator", "ffpros", "ffopportunity"),
recursive = TRUE,
redact_path = TRUE
)
.sitrep(
pkg,
recursive = TRUE,
redact_path = TRUE,
dev_repos = c("https://nflverse.r-universe.dev", "https://ffverse.r-universe.dev")
)
Arguments
pkg |
a character vector naming installed packages, or |
recursive |
a logical indicating whether dependencies of |
redact_path |
a logical indicating whether options that contain "path" in the name should be redacted, default = TRUE |
dev_repos |
Developmental cran-like repos to check, e.g. r-universe repos |
Examples
try({
nflverse_sitrep()
ffverse_sitrep()
.sitrep("cachem")
})
nflverse_sitrep data class
Description
nflverse_sitrep()
returns an S3 class that was created to allow for custom
printing. It will otherwise dispatch to the list
class.
Details
Re-exporting with methods::setOldClass()
allows these dataframes to be used
in S4 generics like those from DBI and jsonlite.
Load .parquet file from a remote connection
Description
Retrieves a parquet file from URL. This function is cached
Usage
parquet_from_url(url)
Arguments
url |
a character url |
Value
a dataframe as parsed by arrow::read_parquet()
Examples
try({
parquet_from_url(
"https://github.com/nflverse/nflverse-data/releases/download/player_stats/player_stats.parquet"
)
})
Alternate player name mappings
Description
A named character vector mapping common alternate names, re-exported from ffscrapr
.
Usage
player_name_mapping
Format
A named character vector
- name attribute
The "alternate" name.
- value attribute
The "correct" name.
Details
You can suggest additions to this table by opening an issue in ffscrapr.
Examples
player_name_mapping[c("Chatarius Atwell", "Robert Kelley")]
Progressively
Description
This function helps add progress-reporting to any function - given function f()
and progressor p()
,
it will return a new function that calls f()
and then (on exiting) will call p()
after every iteration.
This is inspired by purrr's safely
, quietly
, and possibly
function decorators.
Usage
progressively(f, p = NULL)
Arguments
f |
a function to add progressor functionality to. |
p |
a function such as one created by |
Value
a function that does the same as f
but it calls p()
after iteration.
See Also
https://nflreadr.nflverse.com/articles/exporting_nflreadr.html for vignette on exporting nflreadr in packages
Examples
try({ # prevents cran errors
urls <- rep("https://github.com/nflverse/nflverse-data/releases/download/test/combines.csv",3)
lapply(urls, progressively(read.csv, ~cli::cli_progress_step('Loading...')))
read_rosters <- function(urls){
p <- progressr::progressor(along = urls)
lapply(urls, progressively(read.csv, p))
}
progressr::with_progress(read_rosters())
})
Load .qs file from a remote connection
Description
Load .qs file from a remote connection
Usage
qs_from_url(url)
Arguments
url |
a character url |
Value
a dataframe as parsed by qs::qdeserialize()
Examples
try({
qs_from_url(
"https://github.com/nflverse/nflverse-data/releases/download/player_stats/player_stats.qs"
)
})
Load raw filedata from a remote connection
Description
This function allows you to retrieve data from a URL into raw format, which can then be passed into the appropriate file-reading function. Data is memoised/cached for 24 hours.
Usage
raw_from_url(url)
Arguments
url |
a character url |
Value
a raw vector
Examples
try({ # prevents CRAN errors
head(raw_from_url(
"https://github.com/nflverse/nflverse-data/releases/download/test/combines.rds"
),
50)
})
rbindlist but maintain attributes of last file
Description
rbindlist but maintain attributes of last file
Usage
rbindlist_with_attrs(dflist)
Load .rds file from a remote connection
Description
Load .rds file from a remote connection
Usage
rds_from_url(url)
Arguments
url |
a character url |
Value
a dataframe as created by readRDS()
Examples
try({ # prevents cran errors
rds_from_url("https://github.com/nflverse/nflverse-data/releases/download/test/combines.rds")
})
Statistical Mode
Description
Computes the statistical mode, i.e. the value that appears most often in a vector. Returns the first match, if TRUE for multiple values.
Usage
stat_mode(x, ..., na.rm = FALSE)
Arguments
x |
A vector of data values. |
... |
Further arguments, currently unused. |
na.rm |
a logical evaluating to |
Value
The statistical mode with the same type as the input vector x.
Examples
vector_numeric <- sample(1:5, 15, TRUE)
vector_numeric
stat_mode(vector_numeric)
vector_character <- sample(LETTERS[1:5], 15, TRUE)
vector_character
stat_mode(vector_character)
Alternate team abbreviation mappings
Description
A named character vector mapping common alternate team abbreviations.
Usage
team_abbr_mapping
Format
A named character vector
- name attribute
The "alternate" name.
- value attribute
The "correct" name.
Details
You can suggest additions to this table by opening an issue in nflreadr.
See Also
team_abbr_mapping_norelocate
for the same thing but relocations stay in their original cities.
Examples
team_abbr_mapping[c("STL", "OAK","CRD","BLT", "CLV")]
Alternate team abbreviation mappings, no relocation
Description
A named character vector mapping common alternate team abbreviations, but does not follow relocations to their current city.
Usage
team_abbr_mapping_norelocate
Format
A named character vector
- name attribute
The "alternate" name.
- value attribute
The "correct" name.
Details
You can suggest additions to this table by opening an issue in nflreadr.
Examples
team_abbr_mapping_norelocate[c("STL", "OAK","CRD","BLT", "CLV")]