diff --git a/R/simulations.R b/R/simulations.R index 112e10c..70407ba 100644 --- a/R/simulations.R +++ b/R/simulations.R @@ -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, @@ -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, @@ -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, diff --git a/R/simulations_utils.R b/R/simulations_utils.R index 31a7f56..a4e57ed 100644 --- a/R/simulations_utils.R +++ b/R/simulations_utils.R @@ -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 \\ diff --git a/man/nfl_simulations.Rd b/man/nfl_simulations.Rd index 7707efc..10d3f15 100644 --- a/man/nfl_simulations.Rd +++ b/man/nfl_simulations.Rd @@ -86,7 +86,7 @@ to set the grade of verbosity of status reports. They mean: }} } \value{ -An \code{nflseedR_simulation} object containing a list of 6 data frames +An \code{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,