Learn R Programming

nflscrapR (version 1.8.3)

scrape_season_play_by_play: Scrape season play-by-play for a given NFL season (either pre, regular, or post-season)

Description

Depending on the year and type of the given game id, this function returns the play-by-play data available from NFL.com from either JSON (games starting in 2009) or parsed HTML (regular and post-season games starting in 1998, pre-season games starting in 2000). The necessary info regarding the game's play-by-play data to be scraped (type and season) is provided by the scrape_game_ids function. In addition to all of the play-level data provided by the NFL, outputs from the `nflscrapR` expected points and win probability models are also included, allowing an individual to conduct their own analysis with more advanced football statistics. A detailed description of the models methodologies can be found here: https://arxiv.org/abs/1802.00998. This function acts as a wrapper function for calling the scrape_game_play_by_play function over all of the games meeting the criteria of the user's input.

Usage

scrape_season_play_by_play(season, type = "reg", weeks = NULL,
  teams = NULL)

Arguments

season

Numeric 4-digit year associated with an NFL season

type

String indicating the type of game play-by-play, must either be "pre", "reg", or "post" (default is "reg").

weeks

Numeric vector indicating which weeks of preseason (0 to 4 except for 2011 season without Hall of Fame game) or regular season games (1 to 17) to grab (default value of NULL corresponds to selecting all available weeks).

teams

String vector indicating which teams (based on the abbreviation) the function should grab game info for (default value of NULL corresponds to selecting all available teams).

Value

Data frame where each individual row represents a single play in the game containing detailed information depending on the availability of data for the game. See scrape_json_play_by_play and scrape_html_play_by_play for documentation about the columns returned.

Examples

Run this code
# NOT RUN {
# Scrape the play-by-play data for the 2017 Super Bowl by first getting all
# of the post-season game ids then use the required info to scrape the 
# play-by-play data (knowing that it's the last game):
playoff_game_ids_17 <- scrape_game_ids(2017, type = "post")
sb_17_id <- playoff_game_ids_17$game_id[nrow(playoff_game_ids_17)]
sb_17_pbp <- scrape_game_play_by_play(game_id = sb_17_id, type = "post", 
                                      season = 2017)
# }

Run the code above in your browser using DataLab