Skip to content

Commit

Permalink
Combine returned list into data frame for player_match_stats()
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyRStevens committed Jan 17, 2025
1 parent b198438 commit 2e27be7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
6 changes: 3 additions & 3 deletions R/player_match_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand Down Expand Up @@ -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]])
Expand Down
4 changes: 2 additions & 2 deletions man/player_match_stats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions tests/testthat/test-player_match_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down

0 comments on commit 2e27be7

Please sign in to comment.