Title: | Download 'nflverse' Data |
---|---|
Description: | A minimal package for downloading data from 'GitHub' repositories of the 'nflverse' project. |
Authors: | Tan Ho [aut, cre, cph] , Sebastian Carl [aut], John Edwards [ctb], Ben Baldwin [ctb], Thomas Mock [ctb], Lee Sharpe [ctb], Pranav Rajaram [ctb] |
Maintainer: | Tan Ho <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.4.1.05 |
Built: | 2024-11-12 16:20:33 UTC |
Source: | https://github.com/nflverse/nflreadr |
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).
clean_homeaway(dataframe, invert = NULL)
clean_homeaway(dataframe, invert = NULL)
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) |
a dataframe with one row per team (twice as long as the input dataframe)
# 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"))
# 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"))
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
clean_player_names( player_name, lowercase = FALSE, convert_lastfirst = TRUE, use_name_database = TRUE, convert_to_ascii = rlang::is_installed("stringi") )
clean_player_names( player_name, lowercase = FALSE, convert_lastfirst = TRUE, use_name_database = TRUE, convert_to_ascii = rlang::is_installed("stringi") )
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 |
Equivalent to the operation done by ffscrapr::dp_clean_names()
and uses the same player name database.
a character vector of cleaned names
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)
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)
This function standardizes NFL team abbreviations to nflverse defaults. This helps for joins and plotting, especially with the new nflplotR package!
clean_team_abbrs(abbr, current_location = TRUE, keep_non_matches = TRUE)
clean_team_abbrs(abbr, current_location = TRUE, keep_non_matches = TRUE)
abbr |
a character vector of abbreviations |
current_location |
If |
keep_non_matches |
If |
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
).
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)
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)
This function clears the memoised cache of all functions memoised by nflreadr
.
clear_cache() .clear_cache()
clear_cache() .clear_cache()
A success message after clearing the cache.
clear_cache()
clear_cache()
This is a thin wrapper on data.table::fread, but memoised & cached for twenty four hours.
csv_from_url(...)
csv_from_url(...)
... |
Arguments passed on to
|
a dataframe as created by data.table::fread()
try({ # prevents cran errors csv_from_url("https://github.com/nflverse/nflverse-data/releases/download/test/combines.csv") })
try({ # prevents cran errors csv_from_url("https://github.com/nflverse/nflverse-data/releases/download/test/combines.csv") })
A dataframe containing the data dictionary for load_combine()
dictionary_combine
dictionary_combine
An object of class data.frame
with 18 rows and 3 columns.
vignette("Data Dictionary - Combine")
https://nflreadr.nflverse.com/articles/dictionary_combine.html
A dataframe containing the data dictionary for load_contracts()
dictionary_contracts
dictionary_contracts
An object of class data.frame
with 15 rows and 3 columns.
vignette("Data Dictionary - Contracts")
https://nflreadr.nflverse.com/articles/dictionary_contracts.html
A dataframe containing the data dictionary for load_depth_charts()
dictionary_depth_charts
dictionary_depth_charts
An object of class data.frame
with 13 rows and 3 columns.
vignette("Data Dictionary - Depth Charts")
https://nflreadr.nflverse.com/articles/dictionary_depth_charts.html
A dataframe containing the data dictionary for load_draft_picks()
dictionary_draft_picks
dictionary_draft_picks
An object of class data.frame
with 36 rows and 3 columns.
vignette("Data Dictionary - Draft Picks")
https://nflreadr.nflverse.com/articles/dictionary_draft_picks.html
A dataframe containing the data dictionary for load_espn_qbr()
dictionary_espn_qbr
dictionary_espn_qbr
An object of class data.frame
with 23 rows and 3 columns.
vignette("Data Dictionary - ESPN QBR")
https://nflreadr.nflverse.com/articles/dictionary_espn_qbr.html
A dataframe containing the data dictionary for load_ff_opportunity()
dictionary_ff_opportunity
dictionary_ff_opportunity
An object of class data.frame
with 218 rows and 4 columns.
vignette("Data Dictionary - Expected Fantasy Points")
https://nflreadr.nflverse.com/articles/dictionary_ff_opportunity.html
A dataframe containing the data dictionary for load_ff_playerids()
dictionary_ff_playerids
dictionary_ff_playerids
An object of class data.frame
with 35 rows and 3 columns.
vignette("Data Dictionary - FF Player IDs")
https://nflreadr.nflverse.com/articles/dictionary_ff_playerids.html
A dataframe containing the data dictionary for load_ff_rankings()
dictionary_ff_rankings
dictionary_ff_rankings
An object of class data.frame
with 25 rows and 3 columns.
vignette("Data Dictionary - FF Rankings")
https://nflreadr.nflverse.com/articles/dictionary_ff_rankings.html
A dataframe containing the data dictionary for load_ftn_charting()
dictionary_ftn_charting
dictionary_ftn_charting
An object of class data.frame
with 28 rows and 5 columns.
vignette("Data Dictionary - FTN Charting")
https://nflreadr.nflverse.com/articles/dictionary_ftn_charting.html
Other ftn_charting:
load_ftn_charting()
A dataframe containing the data dictionary for load_injuries()
dictionary_injuries
dictionary_injuries
An object of class data.frame
with 16 rows and 3 columns.
vignette("Data Dictionary - Injuries")
https://nflreadr.nflverse.com/articles/dictionary_injuries.html
A dataframe containing the data dictionary for load_nextgen_stats()
dictionary_nextgen_stats
dictionary_nextgen_stats
An object of class data.frame
with 51 rows and 3 columns.
vignette("Data Dictionary - Next Gen Stats")
https://nflreadr.nflverse.com/articles/dictionary_nextgen_stats.html
A dataframe containing the data dictionary for load_participation()
dictionary_participation
dictionary_participation
An object of class data.frame
with 19 rows and 3 columns.
vignette("Data Dictionary - Participation")
https://nflreadr.nflverse.com/articles/dictionary_participation.html
A dataframe containing the data dictionary for load_pbp()
dictionary_pbp
dictionary_pbp
An object of class data.frame
with 372 rows and 3 columns.
vignette("Data Dictionary - PBP")
https://nflreadr.nflverse.com/articles/dictionary_pbp.html
A dataframe containing the data dictionary for load_pfr_passing()
dictionary_pfr_passing
dictionary_pfr_passing
An object of class data.frame
with 28 rows and 3 columns.
https://nflreadr.nflverse.com/articles/dictionary_pfr_passing.html
vignette("Data Dictionary - PFR Passing")
A dataframe containing the data dictionary for load_player_stats()
dictionary_player_stats
dictionary_player_stats
An object of class data.frame
with 48 rows and 2 columns.
vignette("Data Dictionary - Player Stats")
https://nflreadr.nflverse.com/articles/dictionary_player_stats.html
A dataframe containing the data dictionary for load_player_stats()
dictionary_player_stats_def
dictionary_player_stats_def
An object of class data.frame
with 22 rows and 3 columns.
vignette("Data Dictionary - Player Stats Defense")
https://nflreadr.nflverse.com/articles/dictionary_player_stats_def.html
A dictionary translating the shorthand roster status to more verbose explanations of what each status indicates.
dictionary_roster_status
dictionary_roster_status
An object of class data.frame
with 19 rows and 2 columns.
A dataframe containing the data dictionary for load_rosters()
dictionary_rosters
dictionary_rosters
An object of class data.frame
with 25 rows and 3 columns.
vignette("Data Dictionary - Rosters")
https://nflreadr.nflverse.com/articles/dictionary_rosters.html
A dataframe containing the data dictionary for load_schedules()
dictionary_schedules
dictionary_schedules
An object of class data.frame
with 45 rows and 3 columns.
vignette("Data Dictionary - Schedules")
https://nflreadr.nflverse.com/articles/dictionary_schedules.html
A dataframe containing the data dictionary for load_snap_counts()
dictionary_snap_counts
dictionary_snap_counts
An object of class data.frame
with 16 rows and 3 columns.
vignette("Data Dictionary - Snap Counts")
https://nflreadr.nflverse.com/articles/dictionary_snap_counts.html
A dataframe containing the data dictionary for load_trades()
dictionary_trades
dictionary_trades
An object of class data.frame
with 11 rows and 3 columns.
vignette("Data Dictionary - Trades")
https://nflreadr.nflverse.com/articles/dictionary_trades.html
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)
get_current_week(use_date = FALSE)
get_current_week(use_date = FALSE)
use_date |
a logical to determine whether to use date-based heuristics to determine current week, default FALSE (i.e. uses schedule file) |
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.
current nfl regular season week as a numeric
Other Date utils:
most_recent_season()
{ try({ # schedules file as per default requires online access get_current_week() }) # using the date method works offline get_current_week(use_date = TRUE) }
{ try({ # schedules file as per default requires online access get_current_week() }) # using the date method works offline get_current_week(use_date = TRUE) }
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
join_coalesce( x, y, by = NULL, type = c("left", "inner", "full"), ..., by.x = NULL, by.y = NULL, sort = TRUE, incomparables = c(NA, NaN) )
join_coalesce( x, y, by = NULL, type = c("left", "inner", "full"), ..., by.x = NULL, by.y = NULL, sort = TRUE, incomparables = c(NA, NaN) )
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. |
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.
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")
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")
Loads combine data since 2000 courtesy of PFR.
load_combine( seasons = TRUE, file_type = getOption("nflreadr.prefer", default = "rds") )
load_combine( seasons = TRUE, file_type = getOption("nflreadr.prefer", default = "rds") )
seasons |
a numeric vector of seasons to return, default |
file_type |
One of |
A tibble of NFL combine data provided by Pro Football Reference.
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
try({ # prevents cran errors load_combine() })
try({ # prevents cran errors load_combine() })
Loads player contracts from OverTheCap.com
load_contracts(file_type = getOption("nflreadr.prefer", default = "rds"))
load_contracts(file_type = getOption("nflreadr.prefer", default = "rds"))
file_type |
One of |
A tibble of active and non-active NFL player contracts.
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
try({ # prevents cran errors load_contracts() })
try({ # prevents cran errors load_contracts() })
Loads depth charts for each NFL team for each week back to 2001.
load_depth_charts( seasons = most_recent_season(), file_type = getOption("nflreadr.prefer", default = "rds") )
load_depth_charts( seasons = most_recent_season(), file_type = getOption("nflreadr.prefer", default = "rds") )
seasons |
a numeric vector specifying what seasons to return, if |
file_type |
One of |
A tibble of week-level depth charts for each team.
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
try({ # prevents cran errors load_depth_charts(2020) })
try({ # prevents cran errors load_depth_charts(2020) })
Loads every draft pick since 1980 courtesy of PFR.
load_draft_picks( seasons = TRUE, file_type = getOption("nflreadr.prefer", default = "rds") )
load_draft_picks( seasons = TRUE, file_type = getOption("nflreadr.prefer", default = "rds") )
seasons |
a numeric vector of seasons to return, default |
file_type |
One of |
A tibble of NFL draft picks provided by Pro Football Reference.
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
try({ # prevents cran errors load_draft_picks() })
try({ # prevents cran errors load_draft_picks() })
Load ESPN's QBR
load_espn_qbr( seasons = most_recent_season(), summary_type = c("season", "week"), file_type = getOption("nflreadr.prefer", default = "rds") )
load_espn_qbr( seasons = most_recent_season(), summary_type = c("season", "week"), file_type = getOption("nflreadr.prefer", default = "rds") )
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 |
a tibble of ESPN QBR data, summarized according to summary_type
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
load_espn_qbr(2020)
load_espn_qbr(2020)
This function downloads precomputed expected points data from ffopportunity automated releases.
load_ff_opportunity( seasons = most_recent_season(), stat_type = c("weekly", "pbp_pass", "pbp_rush"), model_version = c("latest", "v1.0.0") )
load_ff_opportunity( seasons = most_recent_season(), stat_type = c("weekly", "pbp_pass", "pbp_rush"), model_version = c("latest", "v1.0.0") )
seasons |
a numeric vector of seasons to return, defaults to most recent season. If set to |
stat_type |
one of |
model_version |
one of |
Precomputed expected fantasy points data from the ffopportunity automated releases.
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
try({ # prevents cran errors load_ff_opportunity() load_ff_opportunity(seasons = 2021, stat_type = "pbp_pass", model_version = "v1.0.0") })
try({ # prevents cran errors load_ff_opportunity() load_ff_opportunity(seasons = 2021, stat_type = "pbp_pass", model_version = "v1.0.0") })
Accesses DynastyProcess.com's database of fantasy football player IDs, which help connect nflverse to various other platforms and IDs.
load_ff_playerids()
load_ff_playerids()
a dataframe of player IDs
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
try({ # prevents cran errors load_ff_playerids() })
try({ # prevents cran errors load_ff_playerids() })
Accesses DynastyProcess.com's repository of the latest FP expert consensus rankings - updated on a weekly basis.
load_ff_rankings(type = c("draft", "week", "all"))
load_ff_rankings(type = c("draft", "week", "all"))
type |
one of "draft" (preseason), "week" (this week, inseason), or "all" (full archive) |
a dataframe of expert consensus rankings
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
try({ # prevents cran errors load_ff_rankings() })
try({ # prevents cran errors load_ff_rankings() })
Load any rds/csv/csv.gz/parquet/qs file from a remote URL
load_from_url(url, ..., seasons = TRUE, nflverse = FALSE)
load_from_url(url, ..., seasons = TRUE, nflverse = FALSE)
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. |
a dataframe, possibly of type nflverse_data
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") })
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") })
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
load_ftn_charting( seasons = most_recent_season(), file_type = getOption("nflreadr.prefer", default = "rds") )
load_ftn_charting( seasons = most_recent_season(), file_type = getOption("nflreadr.prefer", default = "rds") )
seasons |
a numeric vector of seasons to return, defaults to most recent season.
If set to |
file_type |
One of |
Play-level manual charting data from FTN Data
FTN Data
FTNData.com
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
try({ # prevents cran errors load_ftn_charting() })
try({ # prevents cran errors load_ftn_charting() })
Data collected from an API for weekly injury report data.
load_injuries( seasons = most_recent_season(), file_type = getOption("nflreadr.prefer", default = "rds") )
load_injuries( seasons = most_recent_season(), file_type = getOption("nflreadr.prefer", default = "rds") )
seasons |
a numeric vector of seasons to return, data available since 2009. Defaults to latest season available. |
file_type |
One of |
a tibble of season-level injury report data.
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
try({# prevents cran errors load_injuries(2020) })
try({# prevents cran errors load_injuries(2020) })
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.
load_nextgen_stats( seasons = TRUE, stat_type = c("passing", "receiving", "rushing"), file_type = getOption("nflreadr.prefer", default = "rds") )
load_nextgen_stats( seasons = TRUE, stat_type = c("passing", "receiving", "rushing"), file_type = getOption("nflreadr.prefer", default = "rds") )
seasons |
a numeric vector specifying what seasons to return, if |
stat_type |
one of |
file_type |
One of |
A tibble of week-level player statistics provided by NFL Next Gen Stats.
Regular season summary is given for week == 0
.
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
try({ # prevents cran errors load_nextgen_stats(stat_type = "passing") load_nextgen_stats(stat_type = "receiving") load_nextgen_stats(stat_type = "rushing") })
try({ # prevents cran errors load_nextgen_stats(stat_type = "passing") load_nextgen_stats(stat_type = "receiving") load_nextgen_stats(stat_type = "rushing") })
Loads data on which officials are assigned to oversee a specific game. Data available from 2015 onwards.
load_officials( seasons = TRUE, file_type = getOption("nflreadr.prefer", default = "rds") )
load_officials( seasons = TRUE, file_type = getOption("nflreadr.prefer", default = "rds") )
seasons |
a numeric vector specifying what seasons to return, if |
file_type |
One of |
A tibble with one row per game per official.
Issues with this data should be filed here: https://github.com/nflverse/nflreadr and it will be triaged appropriately.
try({ # prevents cran errors load_officials() })
try({ # prevents cran errors load_officials() })
Loads participation data from the nflverse-data repository
load_participation( seasons = most_recent_season(), include_pbp = FALSE, file_type = getOption("nflreadr.prefer", default = "rds") )
load_participation( seasons = most_recent_season(), include_pbp = FALSE, file_type = getOption("nflreadr.prefer", default = "rds") )
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 |
A dataframe of participation data, optionally merged with play by play
try({ # prevents cran errors load_participation(seasons = 2020, include_pbp = TRUE) })
try({ # prevents cran errors load_participation(seasons = 2020, include_pbp = TRUE) })
Loads play by play seasons from the nflverse-data repository
load_pbp( seasons = most_recent_season(), file_type = getOption("nflreadr.prefer", default = "rds") )
load_pbp( seasons = most_recent_season(), file_type = getOption("nflreadr.prefer", default = "rds") )
seasons |
A numeric vector of 4-digit years associated with given NFL seasons - defaults to latest season. If set to |
file_type |
One of |
The complete nflfastR dataset as returned by nflfastR::build_nflfastR_pbp()
(see below) for all given seasons
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
try({ # prevents cran errors load_pbp(2019:2020) })
try({ # prevents cran errors load_pbp(2019:2020) })
Loads player level season stats provided by Pro Football Reference starting with the 2018 season, primarily to augment existing nflverse data.
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") )
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") )
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 |
A tibble of player statistics provided by Pro Football Reference that supplements data in nflverse
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
try({ # prevents cran errors load_pfr_advstats() })
try({ # prevents cran errors load_pfr_advstats() })
Load Player Level Weekly Stats
load_player_stats( seasons = most_recent_season(), stat_type = c("offense", "defense", "kicking"), file_type = getOption("nflreadr.prefer", default = "rds") )
load_player_stats( seasons = most_recent_season(), stat_type = c("offense", "defense", "kicking"), file_type = getOption("nflreadr.prefer", default = "rds") )
seasons |
a numeric vector of seasons to return, defaults to most recent season. If set to |
stat_type |
one of |
file_type |
One of |
A tibble of week-level player statistics that aims to match NFL official box scores.
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
try({ # prevents cran errors load_player_stats() load_player_stats(stat_type = "kicking") })
try({ # prevents cran errors load_player_stats() load_player_stats(stat_type = "kicking") })
Load a dataframe of player-level information, including IDs and other mostly-immutable data (birthdates, college, draft position etc.)
load_players(file_type = getOption("nflreadr.prefer", default = "rds"))
load_players(file_type = getOption("nflreadr.prefer", default = "rds"))
file_type |
One of |
A tibble with one row per player.
Issues with this data should be filed here: https://github.com/nflverse/nflreadr and it will be triaged appropriately.
try({ # prevents cran errors load_players() })
try({ # prevents cran errors load_players() })
Load Rosters
load_rosters( seasons = most_recent_season(roster = TRUE), file_type = getOption("nflreadr.prefer", default = "rds") )
load_rosters( seasons = most_recent_season(roster = TRUE), file_type = getOption("nflreadr.prefer", default = "rds") )
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 |
A tibble of season-level roster data.
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
try({ # prevents cran errors load_rosters(2020) })
try({ # prevents cran errors load_rosters(2020) })
Returns week level rosters (rather than latest for a given season as returned by load_rosters()
)
load_rosters_weekly( seasons = most_recent_season(roster = TRUE), file_type = getOption("nflreadr.prefer", default = "rds") )
load_rosters_weekly( seasons = most_recent_season(roster = TRUE), file_type = getOption("nflreadr.prefer", default = "rds") )
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 |
A tibble of weekly roster data.
Issues with this data should be filed here: https://github.com/nflverse/nflverse-data
try({ # prevents cran errors load_rosters_weekly(2020) })
try({ # prevents cran errors load_rosters_weekly(2020) })
This returns game/schedule information as maintained by Lee Sharpe.
load_schedules(seasons = TRUE)
load_schedules(seasons = TRUE)
seasons |
a numeric vector of seasons to return, default |
A tibble of game information for past and/or future games.
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
try({ # prevents cran errors load_schedules(2020) })
try({ # prevents cran errors load_schedules(2020) })
Loads game level snap counts stats provided by Pro Football Reference starting with the 2012 season.
load_snap_counts( seasons = most_recent_season(), file_type = getOption("nflreadr.prefer", default = "rds") )
load_snap_counts( seasons = most_recent_season(), file_type = getOption("nflreadr.prefer", default = "rds") )
seasons |
a numeric vector specifying what seasons to return, if |
file_type |
One of |
A tibble of game-level snap counts provided by Pro Football Reference.
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
try({ # prevents CRAN errors load_snap_counts() })
try({ # prevents CRAN errors load_snap_counts() })
Loads team graphics, colors, and logos - useful for plots!
load_teams(current = TRUE)
load_teams(current = TRUE)
current |
If |
A tibble of team-level image URLs and hex color codes.
Issues with this data should be filed here: https://github.com/nflverse/nflverse-pbp
try({ # prevents cran errors load_teams() })
try({ # prevents cran errors load_teams() })
This returns a table of historical trades as maintained by Lee Sharpe.
load_trades(seasons = TRUE)
load_trades(seasons = TRUE)
seasons |
a numeric vector of seasons to return, default |
A tibble of game information for past and/or future games.
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
load_trades(2020)
load_trades(2020)
A helper function to choose the most recent season available for a given dataset
most_recent_season(roster = FALSE) get_latest_season(roster = FALSE) get_current_season(roster = FALSE)
most_recent_season(roster = FALSE) get_latest_season(roster = FALSE) get_current_season(roster = FALSE)
roster |
Either |
most recent season (a four digit numeric)
Other Date utils:
get_current_week()
A character string defining the default timezone for data across the nflverse
nflverse_data_timezone
nflverse_data_timezone
An object of class character
of length 1.
This function downloads or updates data from the nflverse-data repository releases, creating subfolders that match the release structure.
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" )
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" )
... |
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, |
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! })
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
nflverse_game_id(season, week, away, home)
nflverse_game_id(season, week, away, home)
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 |
A character vector
nflverse_game_id(2022, 2, "LAC", "KC")
nflverse_game_id(2022, 2, "LAC", "KC")
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()
.
nflverse_releases(.token = "default")
nflverse_releases(.token = "default")
.token |
a GitHub API token, |
A dataframe containing release names, release descriptions, and other relevant release information.
try( # avoids cran failures, can skip in normal usage nflverse_releases() )
try( # avoids cran failures, can skip in normal usage nflverse_releases() )
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.
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") )
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") )
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 |
try({ nflverse_sitrep() ffverse_sitrep() .sitrep("cachem") })
try({ nflverse_sitrep() ffverse_sitrep() .sitrep("cachem") })
Retrieves a parquet file from URL. This function is cached
parquet_from_url(url)
parquet_from_url(url)
url |
a character url |
a dataframe as parsed by arrow::read_parquet()
try({ parquet_from_url( "https://github.com/nflverse/nflverse-data/releases/download/player_stats/player_stats.parquet" ) })
try({ parquet_from_url( "https://github.com/nflverse/nflverse-data/releases/download/player_stats/player_stats.parquet" ) })
A named character vector mapping common alternate names, re-exported from ffscrapr
.
player_name_mapping
player_name_mapping
A named character vector
The "alternate" name.
The "correct" name.
You can suggest additions to this table by opening an issue in ffscrapr.
player_name_mapping[c("Chatarius Atwell", "Robert Kelley")]
player_name_mapping[c("Chatarius Atwell", "Robert Kelley")]
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.
progressively(f, p = NULL)
progressively(f, p = NULL)
f |
a function to add progressor functionality to. |
p |
a function such as one created by |
a function that does the same as f
but it calls p()
after iteration.
https://nflreadr.nflverse.com/articles/exporting_nflreadr.html for vignette on exporting nflreadr in packages
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()) })
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
qs_from_url(url)
qs_from_url(url)
url |
a character url |
a dataframe as parsed by qs::qdeserialize()
try({ qs_from_url( "https://github.com/nflverse/nflverse-data/releases/download/player_stats/player_stats.qs" ) })
try({ qs_from_url( "https://github.com/nflverse/nflverse-data/releases/download/player_stats/player_stats.qs" ) })
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.
raw_from_url(url)
raw_from_url(url)
url |
a character url |
a raw vector
try({ # prevents CRAN errors head(raw_from_url( "https://github.com/nflverse/nflverse-data/releases/download/test/combines.rds" ), 50) })
try({ # prevents CRAN errors head(raw_from_url( "https://github.com/nflverse/nflverse-data/releases/download/test/combines.rds" ), 50) })
Load .rds file from a remote connection
rds_from_url(url)
rds_from_url(url)
url |
a character url |
a dataframe as created by readRDS()
try({ # prevents cran errors rds_from_url("https://github.com/nflverse/nflverse-data/releases/download/test/combines.rds") })
try({ # prevents cran errors rds_from_url("https://github.com/nflverse/nflverse-data/releases/download/test/combines.rds") })
Computes the statistical mode, i.e. the value that appears most often in a vector. Returns the first match, if TRUE for multiple values.
stat_mode(x, ..., na.rm = FALSE)
stat_mode(x, ..., na.rm = FALSE)
x |
A vector of data values. |
... |
Further arguments, currently unused. |
na.rm |
a logical evaluating to |
The statistical mode with the same type as the input vector x.
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)
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)
A named character vector mapping common alternate team abbreviations.
team_abbr_mapping
team_abbr_mapping
A named character vector
The "alternate" name.
The "correct" name.
You can suggest additions to this table by opening an issue in nflreadr.
team_abbr_mapping_norelocate
for the same thing but relocations stay in their original cities.
team_abbr_mapping[c("STL", "OAK","CRD","BLT", "CLV")]
team_abbr_mapping[c("STL", "OAK","CRD","BLT", "CLV")]
A named character vector mapping common alternate team abbreviations, but does not follow relocations to their current city.
team_abbr_mapping_norelocate
team_abbr_mapping_norelocate
A named character vector
The "alternate" name.
The "correct" name.
You can suggest additions to this table by opening an issue in nflreadr.
team_abbr_mapping_norelocate[c("STL", "OAK","CRD","BLT", "CLV")]
team_abbr_mapping_norelocate[c("STL", "OAK","CRD","BLT", "CLV")]