### Install Development Dependencies Source: https://ffsimulator.ffverse.com/contributing Installs all necessary development dependencies for the package. Ensure this is run after cloning the repository. ```r devtools::install_dev_deps() ``` -------------------------------- ### R Example: Copying a Template Source: https://ffsimulator.ffverse.com/reference/ffs_copy_template Demonstrates how to use ffs_copy_template to copy a simulation template to a temporary file. This is useful for testing or creating new simulation setups. ```R # \donttest { tmp <- tempfile() ffs_copy_template(tmp) #> ✔ Successfully copied template to /tmp/Rtmpwf16Qh/file1a447f6a29e3! # } ``` -------------------------------- ### Example: Fetching and Displaying Starter Positions Source: https://ffsimulator.ffverse.com/reference/ffs_starter_positions Demonstrates how to establish a connection and then fetch and display the starter positions for a league. This example uses a cached connection for efficiency and includes error handling. ```r # cached examples try({ conn <- .ffs_cache("mfl_conn.rds") ffs_starter_positions(conn) }) ``` -------------------------------- ### R Example: Optimising Lineups with Cached Data Source: https://ffsimulator.ffverse.com/reference/ffs_optimise_lineups This example demonstrates how to use the `ffs_optimise_lineups` function with pre-cached roster scores and lineup constraints. It shows the typical output structure. ```R # \donttest{ # cached examples roster_scores <- .ffs_cache("roster_scores.rds") lineup_constraints <- .ffs_cache("mfl_lineup_constraints.rds") ffs_optimise_lineups(roster_scores, lineup_constraints) ``` -------------------------------- ### Example Usage of ff_simulate_week Source: https://ffsimulator.ffverse.com/reference/ff_simulate_week This example demonstrates how to connect to a fantasy league using mfl_connect and then simulate an upcoming week using ff_simulate_week. It includes a try block to handle potential errors during execution, such as no unplayed weeks being available. ```R # \donttest{ try({ conn <- mfl_connect(2021, 22627) ff_simulate_week(conn, n = 1000, actual_schedule = TRUE) }) # } ``` -------------------------------- ### Import Lineup Constraints Source: https://ffsimulator.ffverse.com/articles/custom Retrieve lineup constraints, such as starting positions and minimum requirements, from your fantasy platform. These can be edited to test hypothetical starting lineup settings. ```r lineup_constraints <- ffs_starter_positions(conn) ``` -------------------------------- ### R Example: Fetching Latest Rankings Source: https://ffsimulator.ffverse.com/reference/ffs_latest_rankings Demonstrates how to call the ffs_latest_rankings function to retrieve the latest FantasyPros expert rankings. The example is wrapped in a try block to prevent potential CRAN-related issues. ```R # \donttest{ try({ # try block to prevent CRAN-related issues ffs_latest_rankings() }) #> ── nflverse FP expert rankings ───────────────────────────────────────────────── #> ℹ Data updated: 2024-10-03 14:21:37 UTC #> # A tibble: 1,324 × 8 #> player fantasypros_id pos team bye ecr sd scrape_date #> #> 1 Brian Branch 25235 DB DET 5 1 0 2024-09-27 #> 2 Jessie Bates III 17544 DB ATL 12 3 1 2024-09-27 #> 3 Julian Love 18243 DB SEA 10 3 0 2024-09-27 #> 4 Derwin James Jr. 17310 DB LAC 5 3.5 1.5 2024-09-27 #> 5 Budda Baker 16733 DB ARI 11 4.5 0.5 2024-09-27 #> 6 Jaquan Brisker 23719 DB CHI 7 8 2 2024-09-27 #> 7 Kyle Dugger 19337 DB NEP 14 8.5 2.5 2024-09-27 #> 8 Kyle Hamilton 23494 DB BAL 14 8.5 1.5 2024-09-27 #> 9 Joshua Metellus 19580 DB MIN 6 10.5 2.5 2024-09-27 #> 10 Xavier McKinney 19216 DB GBP 10 11 2 2024-09-27 #> # ℹ 1,314 more rows # } ``` -------------------------------- ### Install ffsimulator from CRAN Source: https://ffsimulator.ffverse.com/dev Install the stable version of the ffsimulator package from CRAN. ```r install.packages("ffsimulator") # CRAN ``` -------------------------------- ### Install ffsimulator Development Version (remotes) Source: https://ffsimulator.ffverse.com/dev Install the development version of the ffsimulator package using the remotes package. ```r remotes::install_github("ffverse/ffsimulator") ``` -------------------------------- ### Run ff_simulate with Example Data Source: https://ffsimulator.ffverse.com/reference/ff_simulate Example of how to connect to a league and run the ff_simulate function with a specified number of seasons. This code block is wrapped in a try-catch to prevent CRAN-related issues and includes output messages indicating the simulation progress. ```R # \donttest{ try({ conn <- mfl_connect(2021, 22627) ff_simulate(conn, n_seasons = 25) }) # } ``` -------------------------------- ### Install ffsimulator Development Version (pak) Source: https://ffsimulator.ffverse.com/dev Install the development version of the ffsimulator package using the pak package manager. ```r pak::pak("ffverse/ffsimulator") ``` -------------------------------- ### Get Franchises Data Source: https://ffsimulator.ffverse.com/reference/ffs_franchises Fetches franchise data including the league_id, which is necessary for ffsimulator. This example demonstrates how to connect to a league and retrieve its franchises. ```r # \donttest{ # cached examples conn <- .ffs_cache("mfl_conn.rds") try({ ffs_franchises(conn) }) # } ``` -------------------------------- ### Install ffsimulator Development Version (r-universe) Source: https://ffsimulator.ffverse.com/dev Install the development version of the ffsimulator package from the ffverse r-universe repository. ```r install.packages("ffsimulator", repos = "https://ffverse.r-universe.dev") ``` -------------------------------- ### Get League Starter Positions Source: https://ffsimulator.ffverse.com/reference/ffs_starter_positions This function retrieves positional lineup rules for a fantasy football league. It requires an active connection object. ```r ffs_starter_positions(conn) ``` -------------------------------- ### Example Usage of ffs_generate_projections_week Source: https://ffsimulator.ffverse.com/reference/ffs_generate_projections_week Demonstrates how to use the `ffs_generate_projections_week` function with cached ADP outcomes and latest rankings. The function simulates weekly scores for players. ```r # \donttest{ # cached examples adp_outcomes_week <- .ffs_cache("adp_outcomes_week.rds") latest_rankings_week <- .ffs_cache("latest_rankings_week.rds") ffs_generate_projections_week(adp_outcomes_week, latest_rankings_week) #> #> week fantasypros_id player pos team ecr sd rank #> #> 1: 1 17233 Lamar Jackson QB BAL 1.79 0.67 1 #> 2: 9 17233 Lamar Jackson QB BAL 1.79 0.67 1 #> 3: 18 17233 Lamar Jackson QB BAL 1.79 0.67 1 #> 4: 22 17233 Lamar Jackson QB BAL 1.79 0.67 1 #> 5: 30 17233 Lamar Jackson QB BAL 1.79 0.67 1 #> --- #> 276996: 374 19270 Devin Duvernay WR BAL 121.00 15.00 145 #> 276997: 460 19270 Devin Duvernay WR BAL 121.00 15.00 145 #> 276998: 208 19270 Devin Duvernay WR BAL 121.00 15.00 148 #> 276999: 781 19270 Devin Duvernay WR BAL 121.00 15.00 148 #> 277000: 863 18318 Jalen Hurd WR SF 117.67 15.92 150 #> scrape_date projected_score projection gp_model season #> #> 1: 2021-09-06 NA NA 1 1 #> 2: 2021-09-06 NA NA 1 1 #> 3: 2021-09-06 NA NA 1 1 #> 4: 2021-09-06 NA NA 1 1 #> 5: 2021-09-06 NA NA 1 1 #> --- #> 276996: 2021-09-06 NA NA 1 1 #> 276997: 2021-09-06 NA NA 1 1 #> 276998: 2021-09-06 NA NA 1 1 #> 276999: 2021-09-06 NA NA 1 1 #> 277000: 2021-09-06 0.9 0.9 1 1 # } ``` -------------------------------- ### Example Usage of ffs_schedule Source: https://ffsimulator.ffverse.com/reference/ffs_schedule Demonstrates how to use the ffs_schedule function with a pre-established connection object. It caches the connection and then calls ffs_schedule, showing the resulting empty tibble. ```r # \donttest{ # cached examples try({ # try block to prevent CRAN-related issues conn <- .ffs_cache("mfl_conn.rds") ffs_schedule(conn) }) #> # A tibble: 0 × 4 #> # ℹ 4 variables: week , franchise_id , opponent_id , #> # league_id # } ``` -------------------------------- ### Example Usage of ffs_generate_projections Source: https://ffsimulator.ffverse.com/reference/ffs_generate_projections Demonstrates how to use the ffs_generate_projections function with cached adp_outcomes and latest_rankings data. The optional 'rosters' argument can be used to reduce computation. ```R # \donttest{ # cached examples adp_outcomes <- .ffs_cache("adp_outcomes.rds") latest_rankings <- .ffs_cache("latest_rankings.rds") ffs_generate_projections(adp_outcomes, latest_rankings) #> season fantasypros_id player pos team bye ecr #> #> 1: 2 16413 Patrick Mahomes II QB KCC 12 1.32 #> 2: 2 16413 Patrick Mahomes II QB KCC 12 1.32 #> 3: 2 16413 Patrick Mahomes II QB KCC 12 1.32 #> 4: 2 16413 Patrick Mahomes II QB KCC 12 1.32 #> 5: 2 16413 Patrick Mahomes II QB KCC 12 1.32 #> --- #> 994696: 88 19534 Tarik Black WR IND 14 239.50 #> 994697: 88 19534 Tarik Black WR IND 14 239.50 #> 994698: 88 19534 Tarik Black WR IND 14 239.50 #> 994699: 88 19534 Tarik Black WR IND 14 239.50 #> 994700: 88 19534 Tarik Black WR IND 14 239.50 #> sd rank scrape_date week projection gp_model projected_score #> #> 1: 0.69 1 2021-09-03 1 18.82 1 18.82 #> 2: 0.69 1 2021-09-03 2 20.44 0 0.00 #> 3: 0.69 1 2021-09-03 3 18.92 1 18.92 #> 4: 0.69 1 2021-09-03 4 20.44 1 20.44 #> 5: 0.69 1 2021-09-03 5 25.19 1 25.19 #> --- #> 994696: 20.50 243 2021-09-03 10 2.10 0 0.00 #> 994697: 20.50 243 2021-09-03 11 0.00 0 0.00 #> 994698: 20.50 243 2021-09-03 12 0.00 0 0.00 #> 994699: 20.50 243 2021-09-03 13 4.40 0 0.00 #> 994700: 20.50 243 2021-09-03 14 0.00 0 0.00 # } ``` -------------------------------- ### Connect to a Fantasy League and Simulate Seasons Source: https://ffsimulator.ffverse.com/articles/basic Connect to a MyFantasyLeague (MFL) league and run a specified number of seasons and weeks for simulation. This is the primary function to start a simulation. ```r foureight_conn <- mfl_connect(2021, 22627) foureight_sim <- ff_simulate(conn = foureight_conn, n_seasons = 10, n_weeks = 14) foureight_sim ``` -------------------------------- ### Run Basic Fantasy Football Season Simulation Source: https://ffsimulator.ffverse.com/dev Run a fantasy football season simulation using ffsimulator. This example connects to MFL, runs 100 seasons, and plots the results. Other platform connections can be used. ```r library(ffsimulator) library(ggplot2) library(ggridges) mfl_conn <- mfl_connect(season = 2021, league_id = 22627) ## OTHER PLATFORM CONNECTIONS MAY BE USED, FOR EXAMPLE: # sleeper_conn <- sleeper_connect(season = 2021, league_id = "652582284720971776") # flea_conn <- fleaflicker_connect(season = 2021, league_id = 312861) # espn_conn <- espn_connect(season = 2021, league_id = 899513) mfl_sim <- ff_simulate(conn = mfl_conn, n_seasons = 100) plot(mfl_sim) ``` -------------------------------- ### Import Rosters Source: https://ffsimulator.ffverse.com/articles/custom Get roster data and attach a 'fantasypros_id'. This dataframe can be manually edited to simulate hypothetical scenarios like trades before running the simulation. ```r rosters <- ffs_rosters(conn) ``` -------------------------------- ### Generate ADP Outcomes with Simple Games Played Model Source: https://ffsimulator.ffverse.com/reference/ffs_adp_outcomes This example demonstrates how to use `ffs_adp_outcomes` with the default `gp_model = "simple"`. It requires cached scoring history data. ```R # cached data scoring_history <- .ffs_cache("mfl_scoring_history.rds") ffs_adp_outcomes(scoring_history, gp_model = "simple") #> pos rank prob_gp week_outcomes #> #> 1: QB 1 0.9265173 12.92,14.36,13.30,28.48, 9.42,18.32,... #> 2: QB 2 0.9250973 9.40,17.00, 9.70,17.78,-2.00,18.79,... #> 3: QB 3 0.9235976 20.56,21.10,24.46,17.68,33.23,32.94,... #> 4: QB 4 0.9219388 20.56,21.10,24.46,17.68,33.23,32.94,... #> 5: QB 5 0.9200411 20.56,21.10,24.46,17.68,33.23,32.94,... #> --- #> 643: WR 240 0.1362678 1.8,0.9,2.8,1.3,0.3,1.6 #> 644: WR 241 0.1343298 1.0,2.1,1.8,0.9,0.3,1.6 #> 645: WR 242 0.1323911 1.0, 2.1,14.5, 5.7, 6.7, 5.9,... #> 646: WR 243 0.1304520 1.0, 2.1,14.5, 5.7, 6.7, 5.9,... #> 647: WR 244 0.1285126 1.0, 2.1, 5.7, 6.3, 5.2,11.4,... #> player_name #> #> 1: Aaron Rodgers,Deshaun Watson,Deshaun Watson,Patrick Mahomes,Patrick Mahomes,Patrick Mahomes,... #> 2: Baker Mayfield,Aaron Rodgers,Deshaun Watson,Patrick Mahomes,Lamar Jackson,Dak Prescott,... #> 3: Matt Ryan,Baker Mayfield,Aaron Rodgers,Deshaun Watson,Patrick Mahomes,Lamar Jackson,... #> 4: Matt Ryan,Baker Mayfield,Aaron Rodgers,Deshaun Watson,Carson Wentz,Kyler Murray,... #> 5: Matt Ryan,Cam Newton,Baker Mayfield,Aaron Rodgers,Carson Wentz,Kyler Murray,... #> --- #> 643: Ashton Dulin,CJ Board,JoJo Natson,Marcus Kemp #> 644: Fred Brown,Ashton Dulin,JoJo Natson,Marcus Kemp #> 645: Fred Brown,Allen Lazard,Marcus Kemp #> 646: Fred Brown,Allen Lazard,Marcus Kemp #> 647: Fred Brown,Marvin Hall,Allen Lazard,Darrius Shepherd #> fantasypros_id #> #> 1: 9001,16398,16398,16413,16413,16413,... #> 2: 17237,9001,16398,16413,17233,15600,... #> 3: 9444,17237,9001,16398,16413,17233,... #> 4: 9444,17237,9001,16398,15520,18600,... #> 5: 9444,9869,17237,9001,15520,18600,... #> --- #> 643: 18656,16834,16854,16918 #> 644: 17160,18656,16854,16918 #> 645: 17160,17301,16918 #> 646: 17160,17301,16918 #> 647: 17160,16115,17301,19030 ``` -------------------------------- ### Example Usage of ffs_adp_outcomes_week Source: https://ffsimulator.ffverse.com/reference/ffs_adp_outcomes_week Demonstrates how to use the `ffs_adp_outcomes_week` function with cached scoring history data. It shows the resulting dataframe structure including position, rank, weekly outcomes, player names, and FantasyPros IDs. ```R # \donttest{ # cached data scoring_history <- .ffs_cache("mfl_scoring_history.rds") ffs_adp_outcomes_week(scoring_history, pos_filter = c("QB","RB","WR","TE")) #> pos rank week_outcomes #> #> 1: QB 1 7.64, 7.64,32.88,24.48,11.44,24.30,... #> 2: QB 2 32.94, 7.64,32.88,24.48,11.44,24.30,... #> 3: QB 3 32.94, 2.56, 7.64,32.88,24.48,11.44,... #> 4: QB 4 30.80, 6.96,28.76,13.32,32.94, 2.56,... #> 5: QB 5 30.80, 6.96,28.76,13.32,21.10,24.46,... #> --- #> 476: WR 170 -0.2, 1.2, 0.0, 2.1, NA, NA,... #> 477: WR 171 -0.2, 0.0, NA, NA, NA, NA,... #> 478: WR 172 -0.2, 0.0, NA, NA, NA, NA,... #> 479: WR 173 0,NA,NA,NA,NA,NA,... #> 480: WR 174 0,NA,NA,NA,NA,NA,... #> player_name #> #> 1: Matt Ryan,Matt Ryan,Lamar Jackson,Lamar Jackson,Lamar Jackson,Lamar Jackson,... #> 2: Matt Ryan,Matt Ryan,Lamar Jackson,Lamar Jackson,Lamar Jackson,Dak Prescott,... #> 3: Matt Ryan,Matt Ryan,Matt Ryan,Lamar Jackson,Lamar Jackson,Lamar Jackson,... #> 4: Kyler Murray,Matt Ryan,Matt Ryan,Matt Ryan,Lamar Jackson,Lamar Jackson,... #> 5: Kyler Murray,Matt Ryan,Matt Ryan,Matt Ryan,Lamar Jackson,Lamar Jackson,... #> --- #> 476: Deonte Harty,Dwayne Harris,Johnny Holton,Jaleel Scott #> 477: Deonte Harty,Johnny Holton #> 478: Deonte Harty,Johnny Holton #> 479: Johnny Holton #> 480: Johnny Holton #> fantasypros_id #> #> 1: 9444,9444,17233,17233,17233,17233,... #> 2: 9444,9444,17233,17233,17233,15600,... #> 3: 9444,9444,9444,17233,17233,17233,... #> 4: 18600,9444,9444,9444,17233,17233,... #> 5: 18600,9444,9444,9444,17233,17233,... #> --- #> 476: 18876,10004,15803,17260 #> 477: 18876,15803 #> 478: 18876,15803 #> 479: 15803 #> 480: 15803 #> # } ``` -------------------------------- ### Initialize ffscrapr and ffsimulator Source: https://ffsimulator.ffverse.com/articles/custom Sets up the environment by configuring ffscrapr caching and loading necessary libraries. A seed is set for reproducible results. ```r options(ffscrapr.cache = "filesystem") library(ffsimulator) library(ffscrapr) library(tidyverse) library(tictoc) # for timing! set.seed(613) ``` -------------------------------- ### Initialize Git Branch for PR Source: https://ffsimulator.ffverse.com/contributing Creates a new Git branch for your pull request. Replace 'brief-description-of-change' with a concise summary of your modifications. ```r usethis::pr_init("brief-description-of-change") ``` -------------------------------- ### Create GitHub Fork and Clone Source: https://ffsimulator.ffverse.com/contributing Use this function to fork the package repository on GitHub and clone it to your local machine. This is the recommended first step for new contributors. ```r usethis::create_from_github("ffverse/ffsimulator", fork = TRUE) ``` -------------------------------- ### ffs_starter_positions Source: https://ffsimulator.ffverse.com/reference/ffs_starter_positions This function lightly wraps `ffscrapr::ff_starter_positions()` and cleans up some abbreviations (PK -> K). It returns a tidy dataframe of positional lineup rules. ```APIDOC ## ffs_starter_positions ### Description Retrieves a tidy dataframe of positional lineup rules, one row per position with minimum and maximum starters as well as total starter calculations. ### Usage ``` ffs_starter_positions(conn) ``` ### Arguments * **conn** (object) - Required - A connection object as created by `ffscrapr::ff_connect()` and friends. ### Value A tidy dataframe of positional lineup rules, one row per position with minimum and maximum starters as well as total starter calculations. ### Examples ```R # \donttest{ # cached examples try({ conn <- .ffs_cache("mfl_conn.rds") ffs_starter_positions(conn) }) #} ``` ``` -------------------------------- ### Build Schedules and Summarize Results Source: https://ffsimulator.ffverse.com/articles/custom Constructs game schedules for the simulated seasons and then summarizes the weekly and seasonal performance, culminating in a final simulation summary. These steps are computationally fast. ```r schedules <- ffs_build_schedules(franchises = franchises, n_seasons = n_seasons, n_weeks = n_weeks) summary_week <- ffs_summarise_week(optimal_scores, schedules) summary_season <- ffs_summarise_season(summary_week) summary_simulation <- ffs_summarise_simulation(summary_season) ``` -------------------------------- ### Aggregate Simulation Results Source: https://ffsimulator.ffverse.com/articles/custom Aggregates simulation results sequentially, starting from weekly scores, then summarizing by season, and finally by simulation. Each summary function feeds into the next. ```r summary_week <- ffs_summarise_week(optimal_scores, schedules) summary_season <- ffs_summarise_season(summary_week) summary_simulation <- ffs_summarise_simulation(summary_season) ``` -------------------------------- ### Get Rosters with Connection Source: https://ffsimulator.ffverse.com/reference/ffs_rosters Retrieves player rosters using an established connection object. This function is designed to work with various fantasy football platform connection types. ```r conn <- .ffs_cache("mfl_conn.rds") try({ ffs_rosters(conn) }) ``` -------------------------------- ### ff_simulate Source: https://ffsimulator.ffverse.com/reference/ff_simulate Runs fantasy football season simulations using bootstrap resampling. It calculates optimal lineups and returns aggregated results based on historical rankings and nflfastR data. ```APIDOC ## ff_simulate ### Description Runs fantasy football season simulations using bootstrap resampling. It calculates optimal lineups and returns aggregated results based on historical rankings and nflfastR data. ### Arguments * **conn** (connection) - Required - An connection to a league made with `ff_connect()` and friends. * **n_seasons** (integer) - Optional - Number of seasons to simulate, default = 100. * **n_weeks** (integer) - Optional - Number of weeks per season, default = 14. * **best_ball** (logical) - Optional - A logical: are weekly wins based on optimal lineups? * **seed** (integer) - Optional - An integer to control reproducibility. * **gp_model** (character) - Optional - Select between "simple", "none" to apply a model for whether a player played in a given game, defaults to "simple". * **base_seasons** (numeric vector) - Optional - A numeric vector that selects seasons as base data, earliest available is 2012. * **actual_schedule** (logical) - Optional - A logical: use actual ff_schedule? default is FALSE. * **replacement_level** (logical) - Optional - A logical: use best available on waiver as replacement level? defaults to TRUE. * **pos_filter** (character vector) - Optional - A character vector of positions to filter/run, default is c("QB","RB","WR","TE","K"). * **verbose** (logical) - Optional - A logical: print status messages? default is TRUE, configure with options(ffsimulator.verbose). * **return** (character) - Optional - One of c("default", "all") - what objects to return in the output list. ### Value An `ff_simulation` object which can be passed to `plot()` and contains the output data from the simulation. ### Examples ```R # \donttest{ try({ conn <- mfl_connect(2021, 22627) ff_simulate(conn, n_seasons = 25) }) } ``` ``` -------------------------------- ### Generate ADP Outcomes with None Games Played Model Source: https://ffsimulator.ffverse.com/reference/ffs_adp_outcomes This example shows how to use `ffs_adp_outcomes` with `gp_model = "none"`, which assumes every game is played. It also requires cached scoring history data. ```R ffs_adp_outcomes(scoring_history, gp_model = "none") #> pos rank prob_gp week_outcomes #> #> 1: QB 1 1 12.92,14.36,13.30,28.48, 9.42,18.32,... #> 2: QB 2 1 9.40,17.00, 9.70,17.78,-2.00,18.79,... #> 3: QB 3 1 20.56,21.10,24.46,17.68,33.23,32.94,... #> 4: QB 4 1 20.56,21.10,24.46,17.68,33.23,32.94,... #> 5: QB 5 1 20.56,21.10,24.46,17.68,33.23,32.94,... #> --- #> 674: WR 255 1 0,0 ``` -------------------------------- ### Load Required Libraries Source: https://ffsimulator.ffverse.com/articles/basic Load the ffsimulator and ggplot2 libraries before running simulations. ```r library(ffsimulator) library(ggplot2) ``` -------------------------------- ### Connect to League and Simulate a Week Source: https://ffsimulator.ffverse.com/articles/basic Connects to a specified fantasy league and simulates a single week of gameplay. The simulation can be run multiple times (n) for more robust analysis. ```r foureight_conn <- mfl_connect(2021, 22627) foureight_sim_week <- ff_simulate_week(conn = foureight_conn, n = 10) foureight_sim_week ``` -------------------------------- ### ff_connect() Source: https://ffsimulator.ffverse.com/reference/ff_connect Establishes a connection object that can be used with ff_* functions to interact with fantasy football leagues. Refer to the ffscrapr::ff_connect() documentation for detailed usage. ```APIDOC ## ff_connect() ### Description Establishes a connection object to be used with `ff_*` functions. ### Details See `ffscrapr::ff_connect()` for details. ### Value A connection object to be used with `ff_*` functions. ### See Also Other ffscrapr-imports: `espn_connect()`, `ff_scoringhistory()`, `ff_starter_positions()`, `fleaflicker_connect()`, `mfl_connect()`, `sleeper_connect()` ``` -------------------------------- ### Build Fantasy Schedules Function Source: https://ffsimulator.ffverse.com/reference/ffs_build_schedules Generates random head-to-head schedules for a specified number of teams, seasons, and weeks. Use this function to create the foundational schedule for a fantasy simulation. ```R ffs_build_schedules( n_teams = NULL, n_seasons = 100, n_weeks = 14, franchises = NULL, seed = NULL ) ``` ```R # \donttest{ ffs_build_schedules(n_teams = 12, n_seasons = 1, n_weeks = 14) #> season week franchise_id opponent_id #> #> #> #> 1: 1 5 6 10 #> #> 2: 1 5 11 9 #> #> 3: 1 5 2 3 #> #> 4: 1 5 8 7 #> #> 5: 1 5 5 4 #> #> --- #> 164: 1 9 4 10 #> 165: 1 9 7 9 #> 166: 1 9 3 6 #> 167: 1 9 9 7 #> 168: 1 9 10 4 # > # } ``` -------------------------------- ### Run a Fantasy Football Season Simulation Source: https://ffsimulator.ffverse.com/ Loads necessary libraries, connects to the MyFantasyLeague (MFL) platform for a specific season and league, runs 100 season simulations, and plots the results. Other platform connections (Sleeper, Fleaflicker, ESPN) can also be used. ```r library(ffsimulator) library(ggplot2) library(ggridges) mfl_conn <- mfl_connect(season = 2021, league_id = 22627) ## OTHER PLATFORM CONNECTIONS MAY BE USED, FOR EXAMPLE: # sleeper_conn <- sleeper_connect(season = 2021, league_id = "652582284720971776") # flea_conn <- fleaflicker_connect(season = 2021, league_id = 312861) # espn_conn <- espn_connect(season = 2021, league_id = 899513) mfl_sim <- ff_simulate(conn = mfl_conn, n_seasons = 100) plot(mfl_sim) ``` -------------------------------- ### Display League Info Table Source: https://ffsimulator.ffverse.com/articles/basic Shows the structure and sample data for the league_info table, which includes metadata generated by ffscrapr::ff_league(). This table provides details about the fantasy league's settings and characteristics. ```text foureight_sim$league_info #> # A tibble: 1 × 17 #> league_id league_name season league_type franchise_count qb_type idp #> #> 1 22627 Four-Eight Dynasty… 2021 dynasty 12 2QB/SF TRUE #> # ℹ 10 more variables: scoring_flags , best_ball , salary_cap , #> # player_copies , years_active , qb_count , roster_size , #> # league_depth , draft_type , draft_player_pool ``` -------------------------------- ### Push Changes and Create Pull Request Source: https://ffsimulator.ffverse.com/contributing Pushes your committed changes to your fork and initiates the pull request process. Follow the prompts in your browser to complete the PR creation. ```r usethis::pr_push() ``` -------------------------------- ### Load Required Libraries Source: https://ffsimulator.ffverse.com/articles/custom Load the necessary libraries for ffsimulator, ffscrapr, dplyr, and ggplot2. These are essential for running simulations and data manipulation. ```r library(ffsimulator) library(ffscrapr) library(dplyr) library(ggplot2) ``` -------------------------------- ### Check Package with R CMD check Source: https://ffsimulator.ffverse.com/contributing Runs R CMD check to ensure the package passes all checks. It's recommended to resolve any issues before proceeding with further development. ```r devtools::check() ``` -------------------------------- ### Display summary_week Table Source: https://ffsimulator.ffverse.com/articles/basic Shows the structure and sample data for the summary_week table. This table contains weekly performance summaries for each team. ```text foureight_sim$summary_week #> season season_week franchise_name optimal_score #> #> 1: 1 1 Mexico City Space Force 166.65 #> 2: 1 1 Dirty Dgens 145.65 #> 3: 1 1 Alberta Armadillos 108.13 #> 4: 1 1 Electric Woodies 166.51 #> 5: 1 1 Motor City Mutts 148.63 #> --- #> 1676: 10 14 Domination Station 182.70 #> 1677: 10 14 Kill Devil Hills Carpetbaggers 175.64 #> 1678: 10 14 [Redacted] 134.50 #> 1679: 10 14 TB12 64.17 #> 1680: 10 14 Indigo Plateau Elite 205.99 #> lineup_efficiency team_score opponent_score result #> #> 1: 0.691 115.169 76.084 W #> 2: 0.737 107.286 132.011 L #> 3: 0.776 83.912 179.982 L #> 4: 0.793 132.011 107.286 W #> 5: 0.682 101.357 143.900 L #> --- #> 1676: 0.740 135.286 113.904 W #> 1677: 0.795 139.638 100.899 W #> 1678: 0.847 113.904 135.286 L #> 1679: 0.778 49.902 131.653 L #> 1680: 0.760 156.605 79.371 W #> opponent_name allplay_wins allplay_games allplay_pct #> #> 1: Hoth City Tauntauns 5 11 0.455 #> 2: Electric Woodies 3 11 0.273 #> 3: Indigo Plateau Elite 1 11 0.091 #> 4: Dirty Dgens 7 11 0.636 #> 5: Kill Devil Hills Carpetbaggers 2 11 0.182 #> --- #> 1676: [Redacted] 8 11 0.727 #> 1677: Mexico City Space Force 9 11 0.818 #> 1678: Domination Station 5 11 0.455 #> 1679: Electric Woodies 0 11 0.000 #> 1680: Hoth City Tauntauns 11 11 1.000 #> league_id franchise_id optimal_player_id #> #> 1: 22627 0001 13592,14777,14081,15265,14805,13672,... #> 2: 22627 0002 12610,11747,13138,14803,15268,12212,... #> 3: 22627 0003 10700,11644,14075,14087,14806,15261,... #> 4: 22627 0004 10703,13589,13139,13319,13236,13880,... #> 5: 22627 0005 13593,9431,12171,13404,14072,12677,... #> --- #> 1676: 22627 0008 11760,15240,12164,13604,13607,14798,... #> 1677: 22627 0009 14059,7836,11657,13108,13133,15505,... #> 1678: 22627 0010 12140,13116,14223,15254,13680,11671,... #> 1679: 22627 0011 15239,13131,13850,14828,13192,11232,... #> 1680: 22627 0012 14056,8062,11193,12626,13130,14852,... #> optimal_player_score #> #> 1: 17.76,18.54, 8.70,23.70,12.10,17.10,... #> 2: 8.8, 9.7,17.6, 7.7, 8.8,26.2,... #> 3: 10.42, 7.96,10.10, 8.60,17.50,22.30,... #> 4: 24.24,25.12, 0.00,21.40,15.25,13.40,... #> 5: 16.92,14.76,12.10,15.30,11.90,11.85,... #> --- #> 1676: 13.78,12.92, 9.40,22.30,20.30, 9.80,... #> 1677: 29.60,23.64,20.70,11.30,11.70,16.20,... #> 1678: 20.65,38.60, 4.00, 4.40, 7.85, 8.20,... #> 1679: 6.12, 8.20,14.70, 2.40, 2.75, 2.40,... #> 1680: 27.82,25.52, 7.20,18.30,20.70,33.00,... ``` -------------------------------- ### Build Schedules Source: https://ffsimulator.ffverse.com/articles/custom Generates randomized head-to-head schedules for a specified number of seasons, teams, and weeks. It uses the circle method for round robin scheduling and shuffles assignments. ```r schedules <- ffs_build_schedules( n_seasons = n_seasons, n_weeks = n_weeks, seed = NULL, franchises = ffs_franchises(conn) ) ```