Skip to contents

Obtain play-by-play data for a specified time frame from either a saved database or if not defined, using nflreadr::load_pbp().

Usage

get_pbp_data(
  pbp_db = NULL,
  pbp_db_tbl = NULL,
  season = NULL,
  week_min = NULL,
  week_max = NULL
)

Arguments

pbp_db_tbl

Play-by-Play database table name (optional)

season

NFL season (required) to obtain play-by-play data. The season can be defined as a single season, season = 2024. For multiple seasons, use either season = c(2023,2024) or season = 2022:2024.

week_min

Minimum week (required) to define whether pulling a range of weeks or the entire season. Use week_min = 1 for the first week of the season, must be an integer.

week_max

Maximum week (optional) to define a range of weeks to pull from an NFL season. If not defined, the data will be pulled for all weeks, beginning with week_min.

pbp_dp

Play-by-Play database path (optional)

Value

Dataframe with NFL play-by-play data

Details

The function get_pbp_data can be utilized to obtain play-by-play data by either loading from a saved database or using nflreadr::load_pbp(). The data is obtained for a user-defined season or multiple seasons. A range of weeks can also be defined with week_min and week_max. If the entire season is desired, use week_min = 1 and week_max does not need to be defined. To specify loading from a database, define the path to the database with pbp_db as well as the name of the table to load with pbp_db_tbl. To load from a database, you will need to save play-by-play data to a database using the nflfastR function, update_db(). For example, the database is saved by default as pbp_db with a table that is stored containing all play-by-play information called nflfastR_pbp. Assume that the database is saved in project_name/data/. Using the default naming scheme, get_pbp_data can be defined using the database with pbp_db = "data/pbp_db" and pbp_db_tbl = "nflfastR_pbp". Note that these two arguments must be defined as strings. For more information, nflfastR provides an example on using the database in Example 8: Using the built-in database function (https://www.nflfastr.com/articles/nflfastR.html #example-8-using-the-built-in-database-function)

See also

load_pbp Load play-by-play data,

update_db Update or Create a nflfastR Play-by-Play Database

Author

Nolan MacDonald

  • connect Connect to the play-by-play database with the RSQLite package

  • pbp_dbLoad the play-by-play data from the database table

  • pbpPlay-by-play dataframe filtered for season(s) and week(s)