Skip to contents

update_cfb_db() updates or creates a database with cfbfastR play by play data of all completed games since 2014.

Usage

update_cfb_db(
  dbdir = getOption("cfbfastR.dbdirectory", default = "."),
  dbname = "cfb_pbp_db",
  tblname = "cfbfastR_pbp",
  force_rebuild = FALSE,
  db_connection = NULL
)

Arguments

dbdir

Directory in which the database is or shall be located. Can also be set globally with options(cfbfastR.dbdirectory).

dbname

File name of an existing or desired SQLite database within dbdir

tblname

The name of the play by play data table within the database

force_rebuild

Hybrid parameter (logical or numeric) to rebuild parts of or the complete play by play data table within the database (please see details for further information)

db_connection

A DBIConnection object, as returned by DBI::dbConnect() (please see details for further information)

Value

Invisibly returns NULL. The function is called for its side effects.

Details

This function creates and updates a data table with the name tblname within a SQLite database (other drivers via db_connection) located in dbdir and named dbname. The data table combines all play by play data for every available game back to the 2014 season and adds the most recent completed games as soon as they are available for cfbfastR.

The argument force_rebuild is of hybrid type. It can rebuild the play by play data table either for the whole cfbfastR era (with force_rebuild = TRUE) or just for specified seasons (e.g. force_rebuild = c(2019, 2020)). Please note the following behavior:

force_rebuild = TRUE

: The data table with the name tblname will be removed completely and rebuilt from scratch. This is helpful when new columns are added during the Off-Season.

force_rebuild = c(2019, 2020)

: The data table with the name tblname will be preserved and only rows from the 2019 and 2020 seasons will be deleted and re-added. This is intended to be used for ongoing seasons because ESPN's data provider can make changes to the underlying data during the week.

The parameter db_connection is intended for advanced users who want to use other DBI drivers, such as MariaDB, Postgres or odbc. Please note that the arguments dbdir and dbname are dropped in case a db_connection is provided but the argument tblname will still be used to write the data table into the database.

Examples

# Builds every season from 2014 on, several GB, in a SQLite file.
try(update_cfb_db(dbdir = tempdir()))
#> ── Update cfbfastR Play-by-Play Database ───────────── cfbfastR version 3.1.0 ──
#> ℹ 21:15:17 | Can't find the data table "cfbfastR_pbp" in your database. Will load the play by play data from scratch.
#> • 21:15:17 | Starting download of 13 seasons between 2014 and 2026...
#> • 21:17:17 | Checking for missing completed games...
#> ℹ 21:17:32 | You have 14140 games and are missing 84.
#> • 21:17:32 | Starting download of the seasons 2024, 2023, 2025, 2022, and
#> 2020...
#> ℹ 21:18:34 | You have 14140 games and are missing 84.
#> ℹ 21:18:34 | There are still 84 missing games because the data repo isn't ready. Please try again later.
#> ✔ 21:18:34 | Database update completed
#> ℹ 21:18:34 | Path to your db: /tmp/RtmpVXBvz8/cfb_pbp_db
#> ── DONE ────────────────────────────────────────────────────────────────────────