Skip to content

Commit

Permalink
return nfl season for summary method
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcaseb committed Oct 31, 2024
1 parent 48144ee commit d15dd26
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion R/simulations.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
#' For more information, please see the section "Reproducible random number
#' generation (RNG)" in [furrr::furrr_options].
#'
#' @returns An `nflseedR_simulation` object containing a list of 6 data frames
#' @returns An `nflseedR_simulation` object containing a list of 6
#' data frames with the results of all simulated games,
#' the final standings in each simulated season (incl. playoffs and draft order),
#' summary statistics across all simulated seasons, and the simulation parameters. For a full list,
Expand Down Expand Up @@ -150,6 +150,7 @@ nfl_simulations <- function(games,

# VALIDATE INPUT ----------------------------------------------------------
games <- sims_validate_games(games)
nfl_season <- attr(games, "season")
tiebreaker_depth <- rlang::arg_match(tiebreaker_depth)
sim_include <- rlang::arg_match(sim_include)
sim_include <- switch (sim_include,
Expand Down Expand Up @@ -393,6 +394,7 @@ nfl_simulations <- function(games,
"team_wins" = data.table::setDF(team_wins),
"game_summary" = data.table::setDF(game_summary),
"sim_params" = list(
"nfl_season" = nfl_season,
"playoff_seeds" = playoff_seeds,
"simulations" = simulations,
"chunks" = chunks,
Expand Down
7 changes: 5 additions & 2 deletions R/simulations_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ sims_validate_games <- function(games){
"game_type", "week", "away_team", "home_team",
"away_rest", "home_rest", "location", "result"
)
uses_sim <- all(c("sim", required_vars) %in% games_names)
uses_season <- all(c("season", required_vars) %in% games_names)
uses_sim <- all(c("sim", required_vars) %chin% games_names)
uses_season <- all(c("season", required_vars) %chin% games_names)
setattr(games, "uses_season", uses_season)
# we want the season information in attributes for stuff like summary
if (uses_season) setattr(games, "season", unique(games[["season"]]))

if( !any(uses_sim, uses_season) ){
cli::cli_abort(
"The {.arg games} argument has to be a table including one of the \\
Expand Down
2 changes: 1 addition & 1 deletion man/nfl_simulations.Rd

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

0 comments on commit d15dd26

Please sign in to comment.