Package 'espnscrapeR'

Title: Scrapes Or Collects NFL Data From ESPN
Description: Main use case is to collect ESPN QBR for NFL and college football. Alternative functions include getting NFL standings and scraping NFL season-level stats.
Authors: Thomas Mock
Maintainer: Thomas Mock <[email protected]>
License: MIT + file LICENSE
Version: 0.8.0
Built: 2024-08-16 04:15:46 UTC
Source: https://github.com/jthomasmock/espnscrapeR

Help Index


Get ELO ratings from FiveThirtyEight

Description

Get ELO ratings from FiveThirtyEight

Usage

get_538_elo(season = 2020, stat = "weekly_elo")

Arguments

season

character or numeric, must be 2015 or greater

stat

character, must be one of "games", "weekly_elo", "weekly_rating", "distance", "qb_adj_playoff", "qb_adj"

Value

Returns a tibble

Examples

# Get elo for specific season and stat
get_538_elo(season = 2020, stat = "weekly_elo")

Get historical ELO ratings from FiveThirtyEight

Description

Get historical ELO ratings from FiveThirtyEight

Usage

get_538_elo_historical(team = "pit")

Arguments

team

character, team abbreviated name, must be one of "ari", "atl", "bal", "buf", "car", "chi", "cin", "cle", "dal", "den", "det", "gb", "hou", "ind", "jax", "kc", "oak", "lac", "lar", "mia", "min", "ne", "no", "nyg", "nyj", "phi", "pit", "sf", "sea", "tb", "ten", "wsh"

Value

Returns a tibble

Examples

# Get historic elo for specific team
get_538_elo_historical(team = "pit")

Get ESPN athlete info for NFL players

Description

Get ESPN athlete info for NFL players

Usage

get_athlete(athlete_id)

Arguments

athlete_id

The player's unique athlete id

Value

Returns a tibble

Examples

# Get ALL Playoff QBR from 2016 season
get_athlete("2580")

Get ESPN QBR for College football

Description

Get ESPN QBR for College football

Usage

get_college_qbr(season = 2020, type = "season")

Arguments

season

Numeric or character - greater than 2004

type

character - "season" or "weekly"

Value

tibble

Examples

# Get college QBR from 2014 for players at season level
get_college_qbr(season = 2014, type = "season")

# Get weekly college QBR from 2019
# Note the mix of playoffs/bowls and regular season
get_college_qbr(2019, type = "weekly")

Get ESPN NFL depth chart by year and team

Description

Get ESPN NFL depth chart by year and team

Usage

get_depth_chart(season = 2020, team = 23)

Arguments

season

Either numeric or character

team

team_id or team_abb, can be retrieved via get_nfl_teams()

Value

Returns a tibble

Examples

# Get depth chart for 2017 for Pittsburgh
get_depth_chart("2016", team = "PIT")

Get NFL in-game win probabilities for a specific game from ESPN

Description

Get NFL in-game win probabilities for a specific game from ESPN

Usage

get_espn_win_prob(game_id)

Arguments

game_id

Character string - can be acquired from the website of a specific game, or from espnscrapeR::get_nfl_schedule()

Value

Returns a tibble

Examples

# Get win prob from specific game
get_espn_win_prob(game_id = "401030956")

Get ESPN's WR metrics from FiveThirtyEight

Description

Get ESPN's WR metrics from FiveThirtyEight

Usage

get_espn_wr_metrics()

Value

tibble

Examples

raw_metrics <- espnscrapeR::get_espn_wr_metrics()

dplyr::glimpse(raw_metrics)

Get NFL boxscore for a specific game from ESPN's API

Description

Get NFL boxscore for a specific game from ESPN's API

Usage

get_nfl_boxscore(game_id)

Arguments

game_id

character

Value

Returns a tibble

Examples

# Get NFL play-by-play for a specific game
get_nfl_boxscore(game_id = "300912027")

Get NFL boxscore for players for a specific game from ESPN's API

Description

Get NFL boxscore for players for a specific game from ESPN's API

Usage

get_nfl_boxscore_players(game_id)

Arguments

game_id

character

Value

Returns a tibble

Examples

# Get NFL play-by-play for a specific game
get_nfl_boxscore_players(game_id = "300912027")

Get NFL odds for a specific game from ESPN's API

Description

Get NFL odds for a specific game from ESPN's API

Usage

get_nfl_odds(game_id)

Arguments

game_id

character

Value

Returns a tibble

Examples

# Get odds from a specific game
get_nfl_odds(game_id = "400791550")

Get NFL play-by-play for a specific game from ESPN's API

Description

Get NFL play-by-play for a specific game from ESPN's API

Usage

get_nfl_pbp(game_id)

Arguments

game_id

character

Value

Returns a tibble

Examples

# Get NFL play-by-play for a specific game
get_nfl_pbp(game_id = "300912027")

Get ESPN QBR for NFL football

Description

Get ESPN QBR for NFL football

Usage

get_nfl_qbr(season = 2020, week = NA, season_type = "Regular")

Arguments

season

Either numeric or character

week

Either NA to return season or week 1 to 4 for playoffs or 1 to 17 for regular

season_type

Character - either "Regular" or "Playoffs"

Value

Returns a tibble

Examples

# Get ALL Playoff QBR from 2016 season
get_nfl_qbr("2016", season_type = "Playoffs", week = NA)

# Get Regular season QBR for week 4 of 2019
get_nfl_qbr("2019", season_type = "Regular", week = 4)

Get ESPN QBR for NFL football

Description

Get ESPN QBR for NFL football

Usage

get_nfl_qbr_helper(raw_json, week, season, season_type)

Arguments

week

Either NA to return season or week 1 to 4 for playoffs or 1 to 17 for regular

season

Either numeric or character

season_type

Character - either "Regular" or "Playoffs"

Value

Returns a tibble


Get NFL schedule for a specific year from ESPN's API

Description

Get NFL schedule for a specific year from ESPN's API

Usage

get_nfl_schedule(season)

Arguments

season

Either numeric or character

Value

Returns a tibble

Examples

# Get all games from 2018 season, note that this will have some overlap
# between seasons, for example 2018 returns 2018-01-01 to 2018-12-31
get_nfl_schedule(season = "2018")

Get NFL standings for a specific season from ESPN's API

Description

Get NFL standings for a specific season from ESPN's API

Usage

get_nfl_standings(season = 2019, quiet = FALSE)

Arguments

season

Either numeric or character

Value

Returns a tibble

Examples

# Get standings from 2018 season
get_nfl_standings(season = "2018")

# Get standings from 2010 season
get_nfl_standings(2010)

Return all NFL teams with their name, abbreviation,

Description

Return all NFL teams with their name, abbreviation,

Usage

get_nfl_teams()

Value

tibble

Examples

get_nfl_teams()

Get some of Lee Sharpe's datasets from GitHub

Description

Get some of Lee Sharpe's datasets from GitHub

Usage

get_sharpe_data(dataset = "games")

Arguments

dataset

Character only, one of "airports", "closing_lines", "draft_picks", "draft_values", "games", "logos", "pff_pfr_map_v1", "positions", "rosters", "sc_lines", "standings", "teamcolors", "teams", "trades", "win_totals"

Value

tibble

Examples

# Get NFL games and their outcomes
get_sharpe_data(dataset = "games")

# Get team abbreviations/names/etc by year
get_sharpe_data(dataset = "teams")

Apply 'hulk' palette to specific columns in a gt table. The hulk names comes from the idea of a divergin purple and green theme that is colorblind safe and visually appealing. It is a useful alternative to the red/green palette.

Description

Apply 'hulk' palette to specific columns in a gt table. The hulk names comes from the idea of a divergin purple and green theme that is colorblind safe and visually appealing. It is a useful alternative to the red/green palette.

Usage

gt_hulk_color(gt_object, ..., domain = NULL, trim = FALSE, reverse = FALSE)

Arguments

gt_object

An existing gt table object

...

columns to apply color to

trim

trim the palette to give less intense maximal colors

reverse

reverse the color palette. The default is green = high and purple = low, but reverse = TRUE will make purple high and green low.

Value

Returns a gt table

Examples

# basic use
 mtcars |>
   head() |>
   gt::gt() |>
   gt_hulk_color(mpg)

 mtcars |>
   head() |>
   gt::gt() |>
   # trim gives small range of colors
   gt_hulk_color(mpg:disp, trim = TRUE)

 # option to reverse the color palette
 mtcars |>
   head() |>
   gt::gt() |>
   # trim gives small range of colors
   gt_hulk_color(mpg:disp, rev = TRUE)

Apply FiveThirtyEight theme to a gt table

Description

Apply FiveThirtyEight theme to a gt table

Usage

gt_theme_538(data, ...)

Arguments

data

An existing gt table object

...

Optional additional arguments to gt::table_options()

Value

Returns a tibble


Apply ESPN theme to a gt table

Description

Apply ESPN theme to a gt table

Usage

gt_theme_espn(data, ...)

Arguments

data

An existing gt table object

...

Optional additional arguments to gt::table_options()

Value

Returns a tibble


Scrape NFL stats from ESPN

Description

Scrape NFL stats from ESPN

Usage

scrape_espn_stats(season = 2019, stats = "receiving", season_type = "Regular")

Arguments

season

character or numeric - greater than 1990

stats

character - either receiving, passing, or rushing

season_type

character - either Regular or Playoffs

Value

tibble

Examples

scrape_espn_stats(season = 2000, stats = "passing")

Scrape ESPN Pass/Run Block/Rush Win Rates ratings for a specific season from ESPN's site

Description

Scrape ESPN Pass/Run Block/Rush Win Rates ratings for a specific season from ESPN's site

Usage

scrape_espn_win_rate(season = 2022)

Value

Returns a tibble

Examples

# Get off and def pass/run win rates
scrape_espn_win_rate()

Scrape ESPN FPI ratings for a specific season from ESPN's site

Description

Scrape ESPN FPI ratings for a specific season from ESPN's site

Usage

scrape_fpi(season = 2020, stat = "FPI")

Arguments

season

Either numeric or character

stat

One of 'FPI', 'EFF' or 'PROJ'

Value

Returns a tibble

Examples

# Get team offensive and defensive efficiency from 2020 season
scrape_fpi(2020, stat = "EFF")

Scrape ESPN QBR for NFL football

Description

Scrapes QBR tables for NFL QBs by specific week or at season level.

Usage

scrape_nfl_qbr(season = 2019, week = NA, season_type = "Regular")

Arguments

season

Either numeric or character. Must be between 2006 and current season.

week

Either NA to return season, week 1 to 4 for playoffs, or 1 to 17 for regular season.

season_type

Character - either "Regular" or "Playoffs"

Details

This function supercedes 'get_nfl_qbr' due to the ESPN API altering past data.

Value

Returns a tibble

Examples

# Scrape ALL Playoff QBR from 2016 season
scrape_nfl_qbr("2016", season_type = "Playoffs", week = NA)

# Scrape Regular season QBR for week 4 of 2019
scrape_nfl_qbr("2019", season_type = "Regular", week = 4)

Scrape NFL standings for a specific season from ESPN's site

Description

Scrape NFL standings for a specific season from ESPN's site

Usage

scrape_nfl_standings(season, add_superbowls = FALSE)

Arguments

season

Either numeric or character

add_superbowls

Join superbowl winners (appropriate for historical data or after season over)

Value

Returns a tibble

Examples

# Get standings from 2018 season
scrape_nfl_standings(season = "2018")

# Get standings from 2010 season
scrape_nfl_standings(2000, add_superbowls = TRUE)

Scrape NFL weekly outcomes by week

Description

Scrape NFL weekly outcomes by week

Usage

scrape_nfl_weekly_standings(season = 2020, tidy = FALSE)

Arguments

season

character or numeric - greater than 1990

tidy

logical - either TRUE to stack data by game/week or FALSE to return table as is

Value

tibble

Examples

# Here we run w/ tidy = FALSE to get the exact table from PFR
scrape_nfl_weekly_standings(season = 2020, tidy = FALSE)

# Here we scrape the outcome and stack the games on top of eachother
scrape_nfl_weekly_standings(season = 2020, tidy = TRUE)

Scrape NFL superbowl winners for all years

Description

Scrape NFL superbowl winners for all years

Usage

scrape_superbowls()

Value

Returns a tibble

Examples

# Get superbowls
scrape_superbowls()

Scrape NFL stats from nfl.com at the team level.

Description

Please note that the column names are identical between offense/defense and you should reference the 'role' column for offensive or defensive stats.

Usage

scrape_team_stats_nfl(season = 2019, stats = "passing", role = "offense")

Arguments

season

character or numeric - greater than 1971, note that some data is missing for earlier seasons.

stats

character - either "passing", "rushing", "receiving", "scoring", "downs"

role

character - "offense" or "defense"

Value

tibble

Examples

# Get the NFL.com game-level stats for offense in 2018
scrape_team_stats_nfl(season = 2018, stats = "passing", role = "offense")

# Get the NFL.com team-level passing stats for defense in 2014
scrape_team_stats_nfl(season = "2014", stats = "rushing", role = "defense")

Scrape weekly NFL leaders stats from ESPN

Description

Scrape weekly NFL leaders stats from ESPN

Usage

scrape_weekly_leaders(season = 2019, week = 1, stats = "passing")

Arguments

season

character or numeric - greater than 2002

week

character or numeric - 1 to 17 for regular season

stats

character - either receiving, passing, or rushing

Value

tibble

Examples

scrape_weekly_leaders(season = 2002, stats = "passing", week = 1)