From 2e27be7c19da7c70a716cc90eac5118eda6362f8 Mon Sep 17 00:00:00 2001 From: "Jeffrey R. Stevens" Date: Fri, 17 Jan 2025 10:49:39 -0600 Subject: [PATCH] Combine returned list into data frame for player_match_stats() --- R/player_match_stats.R | 6 +++--- man/player_match_stats.Rd | 4 ++-- tests/testthat/test-player_match_stats.R | 16 ++++++---------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/R/player_match_stats.R b/R/player_match_stats.R index 125975b..4fc23b5 100644 --- a/R/player_match_stats.R +++ b/R/player_match_stats.R @@ -12,8 +12,8 @@ #' @inheritParams player_season_stats #' #' @returns -#' By default, returns list with two data frames: home and away team match -#' statistics. If team is specified, only single data frame is returned. +#' By default, returns data frame that includes both home and away team match +#' statistics. If team is specified, only that team's data are returned. #' #' @export #' @@ -122,7 +122,7 @@ player_match_stats <- function(contest = NULL, # subset a single team's data when requested if (is.null(team)) { - return(stats_list) + return(purrr::list_rbind(stats_list)) } else { if (!team %in% c(away_team, home_team)) cli::cli_abort("Enter valid team for contest {contest}: \"{away_team}\" or \"{home_team}\".") return(stats_list[[team]]) diff --git a/man/player_match_stats.Rd b/man/player_match_stats.Rd index 60f75b5..6d8eaf9 100644 --- a/man/player_match_stats.Rd +++ b/man/player_match_stats.Rd @@ -26,8 +26,8 @@ statistics.} for example "WVB" for women's volleyball and "MVB" for men's volleyball).} } \value{ -By default, returns list with two data frames: home and away team match -statistics. If team is specified, only single data frame is returned. +By default, returns data frame that includes both home and away team match +statistics. If team is specified, only that team's data are returned. } \description{ The NCAA's page for a match/contest includes a tab called diff --git a/tests/testthat/test-player_match_stats.R b/tests/testthat/test-player_match_stats.R index 0aef814..b262d76 100644 --- a/tests/testthat/test-player_match_stats.R +++ b/tests/testthat/test-player_match_stats.R @@ -7,18 +7,14 @@ test_that("player_match_stats() works", { suppressWarnings(hawaii2023 <- player_match_stats(contest = "4475421", team = "Hawaii", sport = "MVB")) - expect_equal(final2024$Louisville$Player[1], + expect_equal(final2024$Player[1], "Nayelis Cabello") - expect_equal(final2024$Louisville$Assists[1], + expect_equal(final2024$Assists[1], 31) - expect_equal(final2024b$`Penn St.`$Player[1], - "Ava Falduto") - expect_equal(final2024b$`Penn St.`$Assists[1], - 2) - expect_equal(nrow(final2024$Louisville), - 14) - expect_equal(nrow(final2024b$Louisville), - 12) + expect_equal(nrow(final2024), + 26) + expect_equal(nrow(final2024b), + 22) expect_equal(nrow(hawaii2023), 11) })