diff --git a/DESCRIPTION b/DESCRIPTION index 80806d5d..97b478f5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: nflfastR Title: Functions to Efficiently Access NFL Play by Play Data -Version: 4.5.0.9002 +Version: 4.5.0.9003 Authors@R: c(person(given = "Sebastian", family = "Carl", diff --git a/NEWS.md b/NEWS.md index 9e2b40f8..f1794cc1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,7 @@ * New implementation of tests to be able to identify breaking changes in reverse dependencies * `calculate_standings()` no more freezes when computing standings from schedules where some games are missing results, i.e. upcoming games. (v4.5.0.9000) * Bug fix that caused problems with upcoming dplyr and tidyselect updates that weren't reverse compatible. +* Significant performance improvements of internal functions. (#402) * Wrap examples in `try()` to avoid CRAN problems. (#404) * Fixed a bug where `calculate_standings()` wasn't able to handle nflverse pbp data. (#404) diff --git a/R/helper_scrape_gc.R b/R/helper_scrape_gc.R index 672e5e35..1cfbd9d5 100644 --- a/R/helper_scrape_gc.R +++ b/R/helper_scrape_gc.R @@ -128,12 +128,8 @@ get_pbp_gc <- function(gameId, dir = NULL, qs = FALSE, ...) { playStatSeq = "sequence" ) - - pbp_stats <- furrr::future_map(unique(stats$playId), function(x, s) { - sum_play_stats(x, s) - }, stats) - - pbp_stats <- dplyr::bind_rows(pbp_stats) + pbp_stats <- lapply(unique(stats$playId), sum_play_stats, stats) + pbp_stats <- data.table::rbindlist(pbp_stats) %>% tibble::as_tibble() # drive info d <- tibble::tibble(drives) %>% diff --git a/R/helper_scrape_nfl.R b/R/helper_scrape_nfl.R index 1ff08ba1..c3576dc1 100644 --- a/R/helper_scrape_nfl.R +++ b/R/helper_scrape_nfl.R @@ -169,13 +169,9 @@ get_pbp_nfl <- function(id, dir = NULL, qs = FALSE, ...) { # if I don't put this here it breaks suppressWarnings( - pbp_stats <- - furrr::future_map(unique(stats$playId), function(x, s) { - sum_play_stats(x, s) - }, stats) + pbp_stats <- lapply(unique(stats$playId), sum_play_stats, stats) ) - - pbp_stats <- dplyr::bind_rows(pbp_stats) + pbp_stats <- data.table::rbindlist(pbp_stats) %>% tibble::as_tibble() combined <- game_info %>% dplyr::bind_cols(plays %>% dplyr::select(-"playStats", -"game_id")) %>% diff --git a/R/helper_tidy_play_stats.R b/R/helper_tidy_play_stats.R index a406f20d..cc9df756 100644 --- a/R/helper_tidy_play_stats.R +++ b/R/helper_tidy_play_stats.R @@ -13,9 +13,9 @@ # @param stats A dataframe including multiple rows for each play_Id holding # gsis stat ids and stats sum_play_stats <- function(play_Id, stats) { - play_stats <- stats %>% filter(.data$playId == play_Id) + play_stats <- stats[stats$playId == play_Id,] - row <- bind_cols(play_id = as.integer(play_Id), tidy_play_stats_row) + row <- c("play_id" = as.integer(play_Id), tidy_play_stats_row) for (index in seq_along(play_stats$playId)) { stat_id <- play_stats$statId[index]