sportsdataverse / cfbfastr Goto Github PK
View Code? Open in Web Editor NEWAn R package to quickly obtain clean and tidy college football play by play data
Home Page: https://cfbfastR.sportsdataverse.org
License: Other
An R package to quickly obtain clean and tidy college football play by play data
Home Page: https://cfbfastR.sportsdataverse.org
License: Other
In order to avoid data mixup's please add the team_id
from the cfbd_team_info
endpoint to all other endpoints where team/school is only included by chr()
Describe the bug
When attempting to pull pbp data from 2002-2020 using the function below and am receiving the error below.
function
pbp <- data.frame()
seasons <- 2002:2020
progressr::with_progress({
future:: plan("multisession")
pbp <-cfbfastR::load_cfbd_pbp(seasons)
})
Error: 'load_cfbd_pbp' is not an exported object from 'namespace:cfbfastR
https://twitter.com/SaiemGilani/status/1390423040077537285?s=20
I have been using cfbfastR for the past couple of weeks and have loaded data from 2015 to 2021. Today however I have been unable to load 2021 data and I believe you should look into this.
Describe the bug
R Studio cannot find the espn_ratings_fpi function even when cfbfastR is loaded.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Return a dataframe with the specified columns
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
Add any other context about the problem here.
To my knowledge, the geom_cfb_logos package used to only be available in the cfbplotR package (see this post for more: https://kazink36.github.io/cfbplotR/reference/geom_cfb_logos.html). However, I recently upgraded my RStudio to Version 2023.12.1+402, which was released on 1/29/2024 (https://posit.co/download/rstudio-desktop/).
Now, when I attempt to run install.packages("cfbplotR"), I see the following:
Warning in install.packages :
package ‘cfbplotR’ is not available for this version of R
As a result, if I wanted to incorporate college football team logos into a ggplot, is it necessary to uninstall this most recent version of RStudio? Or is there another package, whether that means cfbfastR or something else, that allows us to do the trick?
Thanks in advance for any assistance, and thanks to the cfbfastR team's hard work in general for helping out the football analytics community so thoroughly.
Would it be possible to standardize the columns across years?
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
Add any other context about the problem here.
Using the athlete_id
it appears to be very easy to build the headshot url of the player.
I'd suggest to add the following line somewhere in the below given code block
dplyr::mutate(headshot_url = glue::glue("https://a.espncdn.com/i/headshots/college-football/players/full/{.data$athlete_id}.png"))
The cfbd_team_info
function in cfbd_teams.R
receives conference
, only_fbs
, and year
as arguments. However, only conference
and only_fbs
work. year
is not a query parameter according to CFBDATA. As such, this ends up not doing anything when trying to filter for different years. This can be misleading and does not actually have any functionality.
To Reproduce
Call cfbfastR::cfbd_team_info(year=2019)
and cfbfastR::cfbd_team_info(year=2023)
and view results. They will be the same.
Expected behavior
The call with year=2019 should give a list of teams that are active in 2019, and the call with year=2023 should give a list of teams that are active in 2023.
The first screenshot shows the swaggerUI docs for the CFBDATA API. As seen, there is no query parameter for year, only conference.
The second screenshot shows the source code for the teams endpoint in the cfbdata codebase. There is no filter for year, only for conference. This can be seen here https://github.com/CFBD/cfb-api/blob/main/app/team/team.controller.js
In cfbfastR_1.9.0 it only loads certain years of betting data, for example, 2019-2022 but not 2023. However when cross-referenced with the cfbdata website, the betting data can be found there. I also attempted running the code while directly referencing the package (cfbfastR::), as per a previous closed bug report, but to no avail.
To Reproduce
Expected behavior
Should return my dataset named bet_data containing the betting lines data frame
Desktop (please complete the following information):
Describe the bug
When using the cfbd_game_weather function I keep getting a 401 Error code. I have tried changing my input and have restarted my computer and attempted to do the function with different internet connections to no avail. All other of my functions seem to be working fine. My CFBFastR is up to date.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I expected a data frame with data from the function
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
I am relatively new to RStudio and CFBFastR, so it is likely that I am making a dumb mistake, however, I am unable to figure out what.
Describe the bug
When using the cfbd_pbp_data for any data before 2014, I am getting errors.
When running the following:
Input:
tmp <- tibble()
wk <- 3
seas <- "regular"
yr <- 2013
tmp <- cfbd_pbp_data(yr, seas, wk, team = NULL, play_type = NULL, epa_wpa = TRUE), it returns the following error:
Error:
Error in predict.nnet(object, X) : missing values in 'x'
In addition: Warning messages:
1: In log(dat$new_distance[neg_distance]) : NaNs produced
2: In log(dat$new_distance[neg_distance]) : NaNs produced
3: In log(dat$new_distance[neg_distance]) : NaNs produced
4: In log(dat$new_distance[neg_distance]) : NaNs produced
5: In log(dat$new_distance[neg_distance]) : NaNs produced
6: In log(dat$new_distance[neg_distance]) : NaNs produced
Sometimes another error is produced:
Input:
tmp <- tibble()
wk <- 1
seas <- "regular"
yr <- 2012
tmp <- cfbd_pbp_data(yr, seas, wk, team = NULL, play_type = NULL, epa_wpa = TRUE)
Error:
Error in predict.nnet(object, X) : missing values in 'x'
In addition: There were 20 warnings (use warnings() to see them)
The default year for cfbd_metrics_ppa_teams()
isnt noted in the documentation
Describe the bug
When trying to scrape play by play data for week 12 in 2021, the method cfpd_pbp_data throws an error Error in model.frame.default(Terms, newdata, na.action = na.omit, xlev = object$xlevels) : factor down has new levels 5 and does not return any data. It seems that there may be a misinput in the source data.
To Reproduce
Steps to reproduce the behavior:
call cfb_df = cfbd_pbp_data(2021, week=12, season_type="both", epa_wpa=TRUE)
Expected behavior
I expected to get the pbp dataframe. It would be nice to be notified if there are any datapoints that seem wrong (like down=5) so I can remove them, but this is not something that is super important to me.
Desktop (please complete the following information):
When calling cfbfastR::cfbd_game_team_stats()
, some season/week/season type combinations return long data, others return wide data.
cfbfastR::cfbd_game_team_stats(2004, 1, "regular")
#> ── Team stats data from CollegeFootballData.com ────────────── cfbfastR 1.9.0 ──
#> ℹ Data updated: 2022-07-23 17:17:58 PDT
#> # A tibble: 4 × 78
#> game_id school confe…¹ home_…² oppon…³ oppon…⁴ points total…⁵ net_p…⁶ compl…⁷
#> <int> <chr> <chr> <chr> <chr> <chr> <int> <chr> <chr> <chr>
#> 1 2.42e8 Virgi… ACC home USC Pac-10 13 294 180 14-29
#> 2 2.42e8 USC Pac-10 away Virgin… ACC 24 373 284 19-29
#> 3 2.42e8 India… MVFC away Miami … Mid-Am… 0 204 137 18-33
#> 4 2.42e8 Miami… Mid-Am… home Indian… MVFC 49 454 292 24-37
#> # … with 68 more variables: passing_tds <chr>, yards_per_pass <chr>,
#> # passes_intercepted <chr>, interception_yards <chr>, interception_tds <chr>,
#> # rushing_attempts <chr>, rushing_yards <chr>, rush_tds <chr>,
#> # yards_per_rush_attempt <chr>, first_downs <chr>, third_down_eff <chr>,
#> # fourth_down_eff <chr>, punt_returns <chr>, punt_return_yards <chr>,
#> # punt_return_tds <chr>, kick_return_yards <lgl>, kick_return_tds <lgl>,
#> # kick_returns <lgl>, kicking_points <chr>, fumbles_recovered <chr>, …
#> # ℹ Use `colnames()` to see all variable names
cfbfastR::cfbd_game_team_stats(2004, 2, "regular")
#> # A tibble: 2,840 × 7
#> id school conference homeAway points category stat
#> <int> <chr> <chr> <chr> <int> <chr> <chr>
#> 1 242482426 Duke ACC away 12 fumblesRecovered 3
#> 2 242482426 Duke ACC away 12 rushingTDs 1
#> 3 242482426 Duke ACC away 12 passingTDs 0
#> 4 242482426 Duke ACC away 12 kickingPoints 6
#> 5 242482426 Duke ACC away 12 firstDowns 14
#> 6 242482426 Duke ACC away 12 thirdDownEff 2-13
#> 7 242482426 Duke ACC away 12 fourthDownEff 1-2
#> 8 242482426 Duke ACC away 12 totalYards 265
#> 9 242482426 Duke ACC away 12 netPassingYards 115
#> 10 242482426 Duke ACC away 12 completionAttempts 13-22
#> # … with 2,830 more rows
#> # ℹ Use `print(n = ...)` to see more rows
sessionInfo()
#> R version 4.2.1 (2022-06-23 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 22000)
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=English_United States.utf8
#> [2] LC_CTYPE=English_United States.utf8
#> [3] LC_MONETARY=English_United States.utf8
#> [4] LC_NUMERIC=C
#> [5] LC_TIME=English_United States.utf8
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> loaded via a namespace (and not attached):
#> [1] Rcpp_1.0.9 pillar_1.8.0 compiler_4.2.1 highr_0.9
#> [5] tools_4.2.1 digest_0.6.29 lattice_0.20-45 nlme_3.1-157
#> [9] jsonlite_1.8.0 lubridate_1.8.0 evaluate_0.15 lifecycle_1.0.1
#> [13] tibble_3.1.7 mgcv_1.8-40 pkgconfig_2.0.3 rlang_1.0.4
#> [17] Matrix_1.4-1 reprex_2.0.1 cli_3.3.0 DBI_1.1.3
#> [21] rstudioapi_0.13 curl_4.3.2 yaml_2.3.5 xfun_0.31
#> [25] fastmap_1.1.0 janitor_2.1.0 httr_1.4.3 cfbfastR_1.9.0
#> [29] withr_2.5.0 dplyr_1.0.9 stringr_1.4.0 knitr_1.39
#> [33] generics_0.1.3 fs_1.5.2 vctrs_0.4.1 nnet_7.3-17
#> [37] grid_4.2.1 tidyselect_1.1.2 snakecase_0.11.0 glue_1.6.2
#> [41] data.table_1.14.2 R6_2.5.1 fansi_1.0.3 rmarkdown_2.14
#> [45] purrr_0.3.4 tidyr_1.2.0 magrittr_2.0.3 splines_4.2.1
#> [49] htmltools_0.5.3 ellipsis_0.3.2 assertthat_0.2.1 utf8_1.2.2
#> [53] stringi_1.7.8 RcppParallel_5.1.5
The cfbd_game_team_stats is requiring the "team" argument. However, the arguments description state that it is optional.
Expected behavior
I should be able to execute cfbd_game_team_stats with a minimum of the "year" argument as documented in the usage file.
https://cfbfastr.sportsdataverse.org/reference/cfbd_game_team_stats.html
team
(String optional): D-I Team
Screenshots of Error
Error returned from R Studio.
df <- cfbd_game_team_stats(2021)
Request failed [400]. Retrying in 1.1 seconds...
Request failed [400]. Retrying in 1.3 seconds...
2022-11-15 17:43:42: Invalid arguments or no team stats data available!
Desktop (please complete the following information):
cfbd_game_player_stats was silently erroring on a conversion to numeric near the end of the unpacking. Preparing a hotfix, but will need to take a second look at fully unpacking the list cols and converting to numeric in a more robust manner
Describe the bug
When using the cfbd_game_player_stats() function the stat columns should be numeric and the data should be wide, referenced here https://cfbfastr.sportsdataverse.org/reference/cfbd_game_player_stats.html, but the columns import as lists and the category column is still present.
To Reproduce
Run the following code: cfbd_game_player_stats(2013, week = 1, team = "Florida State", category = "passing")
Expected behavior
The data is wider and the stat columns are numeric instead of lists.
Screenshots
I used the vignette examples to show the actual output below:
Desktop (please complete the following information):
Using purrr methods, when year and week are iterated over, due to the saving of the parameters also as column names within the data process, causes renaming issues. Suggest switching year to season and week to wk (or something better)
> pacman::p_load_current_gh("saiemgilani/cfbfastR")
> pacman::p_load(tidyverse, zoo, ggimage, gt)
> library(dplyr)
> library(tidyr)
> library(purrr)
> # Play-by-Play Data Pull --------------------------------------------------
> week_vector <- 1:15
> year_vector <- 2019
> weekly_year_df <- expand.grid(year = year_vector, week = week_vector)
> ### scrape yearly
> year_split <- split(weekly_year_df, weekly_year_df$year)
>
> ### starting time
> tictoc::tic()
>
> for (i in 1:length(year_split)) {
+ i <- 1
+ print(paste0("Working on ", year_split[[i]][1, 1]))
+ future::plan("multisession")
+ progressr::with_progress({
+ year_split[[i]] <- year_split[[i]] %>%
+ dplyr::mutate(
+ pbp = purrr::map2(
+ .x = year,
+ .y = week,
+ cfbd_pbp_data,
+ season_type = "both",
+ epa_wpa = TRUE
+ )
+ )
+ })
+ }
[1] "Working on 2019"
* Start processing of 125 games...
* Start processing of 74 games...
* Start processing of 68 games...
* Start processing of 57 games...
* Start processing of 55 games...
* Start processing of 48 games...
* Start processing of 53 games...
* Start processing of 62 games...
* Start processing of 55 games...
* Start processing of 48 games...
* Start processing of 48 games...
* Start processing of 55 games...
* Start processing of 64 games...
* Start processing of 64 games...
* Start processing of 11 games...
>
> tictoc::toc()
417.23 sec elapsed
> ## (~6-7 minutes)
> year_split <- lapply(year_split, function(x) {
+ x %>% tidyr::unnest(pbp, names_repair = "minimal")
+ })
>
> all_years <- dplyr::bind_rows(year_split)
New names:
* year -> year...1
* week -> week...2
* year -> year...3
* week -> week...4
Describe the bug
cfbd_player_usage() when passing an athlete_id number and year to this function it returns all players from that year.
If passing it the Team identifier along with athlete_id, it returns all players from that team. So it seems the team is being handled correctly but its essentially ignoring the athlete_id variable that's being passed.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
1 2022 4430518 Brannon S~ WR Clem~ ACC 0.0265 0.055 0 0.0281 0.028 0.022 0.024 0.025
Actual Behavior
1 2022 4429020 D.J. Uia~ QB Clem~ ACC 0.571 0.922 0.245 0.537 0.507 0.748 0.458 0.697
2 2022 4431545 Will Shi~ RB Clem~ ACC 0.250 0.0906 0.399 0.302 0.227 0.178 0.301 0.134
3 2022 4431562 Phil Maf~ RB Clem~ ACC 0.117 0.0291 0.199 0.119 0.161 0.037 0.12 0.109
4 2022 5081432 Antonio ~ WR Clem~ ACC 0.0655 0.123 0.0121 0.0632 0.057 0.081 0.048 0.08
5 2022 4426426 Joseph N~ WR Clem~ ACC 0.0577 0.120 0 0.0667 0.047 0.059 0.036 0.065
6 2022 4685413 Cade Klu~ QB Clem~ ACC 0.0499 0.0712 0.0302 0.0281 0.066 0.074 0.072 0.06
7 2022 4426553 Davis Al~ TE Clem~ ACC 0.0499 0.104 0 0.0561 0.024 0.081 0.018 0.065
8 2022 4431210 Beaux Co~ WR Clem~ ACC 0.0468 0.0971 0 0.0281 0.052 0.074 0.036 0.08
9 2022 4686095 Kobe Pace RB Clem~ ACC 0.0421 0.0227 0.0604 0.0421 0.052 0.03 0.042 0.045
10 2022 4431196 Jake Bri~ TE Clem~ ACC 0.0281 0.0583 0 0.0281 0.024 0.037 0.024 0.03
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Smartphone (please complete the following information):
N/A
Additional context
Add any other context about the problem here.
Describe the bug
Using cfbfastR v1.6.4, I can't load in any betting lines data. It might be that I have a deprecated version, but I have not been able to update by any means.
To Reproduce
cfbd_betting_lines(year = 2020)
2022-04-09 11:41:21: Invalid arguments or no betting lines data available!
Expected behavior
Betting lines from 2020 should be loaded
Describe the bug
The EPA on punt plays does not seem to be factoring correctly.
To Reproduce
Expected behavior
For punt plays that net out to around 40 yards, the EPA should be minimal.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
Add any other context about the problem here.
Would it be possible to add the "rows_per_team" argument to the cfbd_stats_game_advanced endpoint? This same argument is in the cfbd_game_team_stats endpoint. It would make joining them much easier.
All "cfbd_" functions return the following error:
team_info <- cfbd_team_info(year = 2021)
Error in curl::curl_fetch_memory(url, handle = handle): SSL certificate problem: certificate has expired
Request failed [ERROR]. Retrying in 1 seconds...
Is your feature request related to a problem? Please describe.
Today when I want epa or wpa data, I call cfbd_pbp_data
for each week, sometimes going back several seasons. For each week, epa/wpa numbers are calculated by the function call, taking a minute or more per week.
Describe the solution you'd like
Precalculate the epa/wpa numbers and store them with the base data coming from the API. So when I call cfbd_pbp_data
it only takes a few seconds to download the data from the API.
Describe alternatives you've considered
N/A
Additional context
nflfastr precalculates epa/wpa numbers which makes it quicker to get historical data.
Describe the bug
espn_ratings_fpi
not in CRAN install
To Reproduce
install.packages("cfbfastR")
library(cfbfastR)
cfbfastR::espn_ratings_fpi(year = 2018)
Expected behavior
For this function to be available
https://saiemgilani.github.io/cfbfastR/reference/espn_ratings.html
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
other attached packages:
[1] cfbfastR_1.6.4
It looks like an update to the data repo on April 18th dropped the "season" column in the games_in_data_repo.csv
that is called in the load_games function. Subsequently, this is causing issues in the update_cfb_db
function.
Error:
Error: Problem with `filter()` input `..1`.
Input `..1` is `.data$season >= 2014`.
Column `season` not found in `.data`
I was reading over the documentation for the cfb_pbp_data()
function and noticed that it's supposed to return 351 variables. However, upon using it, I only obtain 56 columns for the year 2023 (additional testing in prior years 2020 and 2018 provided the same result.)
I am using:
cfbfastR
version 1.9.0glimpse()
on the 2023 cfb_pbp_data()
data.I apologize if this is the result of me missing an argument somewhere! Thank you!
When you call cfbd_stats_game_advanced()
with a valid value but receive an empty response (e.g., no games yet for 2023), the return value is an empty list. A valid response to the cfbd_stats_game_advanced
returns a cfbfastR_data object. For example:
tibble(year = 2021:2023) %>%
mutate(stats = map(year, ~ cfbd_stats_game_advanced(year = .x, season_type = "both")))
2023-04-08 12:49:21:Invalid arguments or no game advanced stats data available!
# A tibble: 3 × 2
year stats
<int> <list>
1 2021 <cfbfstR_ [1,692 × 60]>
2 2022 <cfbfstR_ [2,842 × 60]>
3 2023 <list [0]>
This function does throw a warning -- but in returning objects of different types, it can cause errors in downstream processing that expects objects of the same type. For example, trying to unnest the result above generates a type conflict error:
> tibble(year = 2021:2023) %>%
+ mutate(stats = map(year, ~ cfbd_stats_game_advanced(year = .x, season_type = "both"))) %>%
+ unnest(stats)
2023-04-08 12:52:50:Invalid arguments or no game advanced stats data available!
Error in `list_unchop()`:
! Can't combine `x[[1]]` <tbl_df> and `x[[3]]` <list>.
Expected behavior
The function should either throw an error when no stats are available, or it should return the same object type as a non-empty response (i.e., cfbfastR_data). I suggest returning an empty cfbfastR_data object -- a well-formed query about a valid year (e.g., the current year) in which no games happen to have been played yet should be empty, not an error. In the example above, the correct response gets returned (stats for games in two of the three seasons specified, and none for the last) but the object type conflict prevents their combination in later processing. Expected behavior would look something like this:
tibble(year = 2021:2023) %>%
mutate(stats = map(year, ~ cfbd_stats_game_advanced(year = .x, season_type = "both")))
2023-04-08 12:49:21: Invalid arguments or no game advanced stats data available!
# A tibble: 3 × 2
year stats
<int> <list>
1 2021 <cfbfstR_ [1,692 × 60]>
2 2022 <cfbfstR_ [2,842 × 60]>
3 2023 <cfbfstR_ [0 × 60]>
On functions where year
is a parameter please add the minimum integer where the endpoint will work. This number varies across endpoints
cfbfastR::cfbd_pbp_data()
reports erroneous values for the number of points scored on a drive for some plays. For example:
cfbfastR::cfbd_pbp_data(year = 2021, season_type = "regular", week = 3) |>
dplyr::filter(play_type == "Defensive 2pt Conversion") |>
dplyr::pull(drive_pts)
#> [1] 7
I have a dataframe of all plays loaded in my local environment and the only possible values for drive_pts
appear to be -7, -2, 0, 3, or 7 -- impossible given 1) missed extra points resulting in -6 and 6, 2) successful and missed two-point conversions resulting in -8, -6, 6, or 8, and 3) defensive 2 point and 1 point conversions, resulting in -5, -4, 4, and 5. Some of these possibilities are too rare to have occurred in the dataset, but others -- like 8 -- should be present in the dataframe but are not.
Describe the bug
cfbd_game_player_stats giving 400 error. No other cfbd function is throwing said error.
To Reproduce
Steps to reproduce the behavior:
In R
install.packages('cfbfastR')
library(cfbfastR)
cfbd_game_player_stats(2021)
Expected behavior
Expect to load a dataframe.
Desktop (please complete the following information):
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.