Learn R Programming

nflreadr

nflreadr is a minimal package for downloading data from nflverse repositories. It includes caching, optional progress updates, and data dictionaries.

Please note that nflverse data repositories have been reorganized and pushed towards the nflverse-data repo, and v1.2.0+ is the minimum version that supports this change. We encourage all users to upgrade to this version immediately.

For Python access to nflverse data, please check out nfl-data-py - maintained by Cooper Adams.

Installation

Install the stable version from CRAN with:

install.packages("nflreadr")

Install the development version from GitHub with:

install.packages("nflreadr", repos = c("https://nflverse.r-universe.dev", getOption("repos")))

# or use remotes/devtools
# install.packages("remotes")
remotes::install_github("nflverse/nflreadr")

Usage

The main functions of nflreadr are prefixed with load_.

library(nflreadr)

load_pbp(2021)
#> ── nflverse play by play data ──────────────────────────────────────────────────
#> ℹ Data updated: 2022-09-27 04:35:02 PDT
#> # A tibble: 50,712 × 372
#>    play_id game_id     old_game_id home_team away_team season_type  week posteam
#>      <dbl> <chr>       <chr>       <chr>     <chr>     <chr>       <int> <chr>  
#>  1       1 2021_01_AR… 2021091207  TEN       ARI       REG             1 <NA>   
#>  2      40 2021_01_AR… 2021091207  TEN       ARI       REG             1 TEN    
#>  3      55 2021_01_AR… 2021091207  TEN       ARI       REG             1 TEN    
#>  4      76 2021_01_AR… 2021091207  TEN       ARI       REG             1 TEN    
#>  5     100 2021_01_AR… 2021091207  TEN       ARI       REG             1 TEN    
#>  6     122 2021_01_AR… 2021091207  TEN       ARI       REG             1 TEN    
#>  7     152 2021_01_AR… 2021091207  TEN       ARI       REG             1 ARI    
#>  8     181 2021_01_AR… 2021091207  TEN       ARI       REG             1 ARI    
#>  9     218 2021_01_AR… 2021091207  TEN       ARI       REG             1 ARI    
#> 10     253 2021_01_AR… 2021091207  TEN       ARI       REG             1 ARI    
#> # ℹ 50,702 more rows
#> # ℹ 364 more variables: posteam_type <chr>, defteam <chr>, side_of_field <chr>,
#> #   yardline_100 <dbl>, game_date <chr>, quarter_seconds_remaining <dbl>,
#> #   half_seconds_remaining <dbl>, game_seconds_remaining <dbl>,
#> #   game_half <chr>, quarter_end <dbl>, …

load_player_stats(2021)
#> ── nflverse player stats: offense ──────────────────────────────────────────────
#> ℹ Data updated: 2023-02-28 01:26:47 PST
#> # A tibble: 5,698 × 52
#>    player_id  player_name player_display_name position position_group
#>    <chr>      <chr>       <chr>               <chr>    <chr>         
#>  1 00-0019596 T.Brady     Tom Brady           QB       QB            
#>  2 00-0019596 T.Brady     Tom Brady           QB       QB            
#>  3 00-0019596 T.Brady     Tom Brady           QB       QB            
#>  4 00-0019596 T.Brady     Tom Brady           QB       QB            
#>  5 00-0019596 T.Brady     Tom Brady           QB       QB            
#>  6 00-0019596 T.Brady     Tom Brady           QB       QB            
#>  7 00-0019596 T.Brady     Tom Brady           QB       QB            
#>  8 00-0019596 T.Brady     Tom Brady           QB       QB            
#>  9 00-0019596 T.Brady     Tom Brady           QB       QB            
#> 10 00-0019596 T.Brady     Tom Brady           QB       QB            
#> # ℹ 5,688 more rows
#> # ℹ 47 more variables: headshot_url <chr>, recent_team <chr>, season <int>,
#> #   week <int>, season_type <chr>, completions <int>, attempts <int>,
#> #   passing_yards <dbl>, passing_tds <int>, interceptions <dbl>, …

Data Sources

Data accessed by this package is stored on GitHub and can typically be found in one of the following repositories:

For a full list of functions, please see the reference page.

This data is maintained by the nflverse project team and is primarily automated via GitHub Actions. You can check the status and schedules page here: https://github.com/nflverse/nflverse-data

Configuration

The following options help configure default nflreadr behaviours.

options(nflreadr.verbose) 
# TRUE/FALSE to silence messages such as cache warnings
options(nflreadr.cache) 
# one of "memory", "filesystem", or "off"
options(nflreadr.prefer) 
# one of "qs", "rds", "parquet", or "csv"
options(nflreadr.download_path)
# defaults to current working directory - change to specify where `nflverse_download()` places data.

You can also configure nflreadr to display progress messages with the progressr package, e.g.

progressr::with_progress(load_rosters(seasons = 2010:2020))
 |========            |  40%

Getting help

The best places to get help on this package are:

Contributing

Many hands make light work! Here are some ways you can contribute to this project:

Terms of Use

The R code for this package is released as open source under the MIT License. NFL data accessed by this package belong to their respective owners, and are governed by their terms of use.

Copy Link

Version

Install

install.packages('nflreadr')

Monthly Downloads

2,005

Version

1.4.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Tan Ho

Last Published

July 29th, 2024

Functions in nflreadr (1.4.1)

dictionary_player_stats

Data Dictionary: Player Stats
.sitrep_pkg_deps

Show dependency versions of installed packages
load_contracts

Load Historical Player Contracts from OverTheCap.com
load_depth_charts

Load Weekly Depth Charts
load_from_url

Load any rds/csv/csv.gz/parquet/qs file from a remote URL
load_ff_rankings

Load Latest FantasyPros Rankings
load_officials

Load Officials
load_nextgen_stats

Load Player Level Weekly NFL Next Gen Stats
.sitrep_pkg_opts

Show options for installed packages
load_teams

Load NFL Team Graphics, Colors, and Logos
join_coalesce

Coalescing join
load_injuries

Load Injury Reports
load_ftn_charting

Load FTN Charting Data
dictionary_schedules

Data Dictionary: Schedules
dictionary_snap_counts

Data Dictionary: Snap Counts
get_current_week

Get Current Week
load_players

Load Players
load_espn_qbr

Load ESPN's QBR
load_player_stats

Load Player Level Weekly Stats
load_draft_picks

Load Draft Picks from PFR
load_rosters

Load Rosters
dictionary_player_stats_def

Data Dictionary: Player Stats Defense
load_trades

Load Trades
progressively

Progressively
load_schedules

Load Game/Schedule Data
rds_from_url

Load .rds file from a remote connection
load_rosters_weekly

Load Weekly Rosters
dictionary_trades

Data Dictionary: Trades
load_snap_counts

Load Snap Counts from PFR
parquet_from_url

Load .parquet file from a remote connection
team_abbr_mapping_norelocate

Alternate team abbreviation mappings, no relocation
player_name_mapping

Alternate player name mappings
.for_cran

CRAN setup code
nflverse_sitrep

Get a Situation Report on System, nflverse/ffverse Package Versions and Dependencies
nflverse_data-class

nflverse data class
nflreadr-package

nflreadr: Download 'nflverse' Data
stat_mode

Statistical Mode
qs_from_url

Load .qs file from a remote connection
team_abbr_mapping

Alternate team abbreviation mappings
load_pfr_advstats

Load Advanced Stats from PFR
load_ff_opportunity

Load Expected Fantasy Points
raw_from_url

Load raw filedata from a remote connection
load_ff_playerids

Load Fantasy Player IDs
nflverse_game_id

Compute nflverse Game Identifiers
nflverse_download

Bulk download utilities via piggyback
load_combine

Load Combine Data from PFR
nflverse_releases

List all available nflverse releases
load_pfr_passing

Load Advanced Passing Stats from PFR
dictionary_rosters

Data Dictionary: Rosters
load_pbp

Load Play By Play
most_recent_season

Get Latest Season
load_participation

Load Participation Data
nflverse_sitrep-class

nflverse_sitrep data class
rbindlist_with_attrs

rbindlist but maintain attributes of last file
clean_homeaway

Clean Home/Away in dataframes into Team/Opponent dataframes
clean_player_names

Create Player Merge Names
dictionary_depth_charts

Data Dictionary: Depth Charts
csv_from_url

Load .csv / .csv.gz file from a remote connection
clean_team_abbrs

Standardize NFL Team Abbreviations
dictionary_ff_rankings

Data Dictionary: Fantasy Football Rankings
dictionary_participation

Data Dictionary: Participation
dictionary_nextgen_stats

Data Dictionary: Next Gen Stats
dictionary_combine

Data Dictionary: Combine
dictionary_pfr_passing

Data Dictionary: PFR Passing
dictionary_contracts

Data Dictionary: Contracts
dictionary_pbp

Data Dictionary: Play by Play
dictionary_injuries

Data Dictionary: Injuries
dictionary_ftn_charting

Data Dictionary: FTN Charting Data
clear_cache

Clear function cache
dictionary_ff_opportunity

Data Dictionary: Expected Fantasy Points
dictionary_ff_playerids

Data Dictionary: Fantasy Player IDs
dictionary_draft_picks

Data Dictionary: Draft Picks
dictionary_espn_qbr

Data Dictionary: ESPN QBR