An R Client for Fantasy Football League APIs

Helps access various Fantasy Football APIs (currently MFL, Sleeper, Fleaflicker, and eventually ESPN, Yahoo, potentially others) by handling authentication/rate-limiting/caching, forming appropriate calls, and returning tidy dataframes which can be easily connected to other data sources.

Installation

Version 1.2.0 is now on CRAN 🎉 and can be installed with:

install.packages("ffscrapr")
# or from GitHub release with the remotes package # install.packages("remotes")
remotes::install_github("dynastyprocess/ffscrapr",ref = "v1.2.0")

Install the development version from GitHub with:

remotes::install_github("dynastyprocess/ffscrapr")

The dev version has a separate documentation site here.

Usage

All ffscrapr functions start with a connection object created by ff_connect(), which stores connection, authentication, and other user-defined parameters. This object is used by all other functions to help return the correct data.

library(ffscrapr)
ssb <- ff_connect(platform = "mfl", league_id = "54040", season = 2020)

# Get a summary of league settings
ff_league(ssb) %>% str()
#> tibble [1 x 13] (S3: tbl_df/tbl/data.frame)
#>  $ league_id      : chr "54040"
#>  $ league_name    : chr "The Super Smash Bros Dynasty League"
#>  $ franchise_count: num 14
#>  $ qb_type        : chr "1QB"
#>  $ idp            : logi FALSE
#>  $ scoring_flags  : chr "0.5_ppr, TEPrem, PP1D"
#>  $ best_ball      : logi TRUE
#>  $ salary_cap     : logi FALSE
#>  $ player_copies  : num 1
#>  $ years_active   : chr "2018-2020"
#>  $ qb_count       : chr "1"
#>  $ roster_size    : num 28
#>  $ league_depth   : num 392

# Get rosters
ff_rosters(ssb)
#> # A tibble: 439 x 11
#>   franchise_id franchise_name player_id player_name pos   team    age
#>   <chr>        <chr>          <chr>     <chr>       <chr> <chr> <dbl>
#> 1 0001         Team Pikachu   13189     Engram, Ev~ TE    NYG    26.2
#> 2 0001         Team Pikachu   11680     Landry, Ja~ WR    CLE    28  
#> 3 0001         Team Pikachu   14085     Pollard, T~ RB    DAL    23.6
#> 4 0001         Team Pikachu   13645     Smith, Tre~ WR    NOS    24.9
#> 5 0001         Team Pikachu   12110     Brate, Cam~ TE    TBB    29.4
#> # ... with 434 more rows, and 4 more variables: roster_status <chr>,
#> #   drafted <chr>, draft_year <chr>, draft_round <chr>

# Get transactions
ff_transactions(ssb)
#> # A tibble: 891 x 12
#>   timestamp           type  type_desc franchise_id franchise_name player_id
#>   <dttm>              <chr> <chr>     <chr>        <chr>          <chr>    
#> 1 2020-11-22 19:29:36 FREE~ added     0009         Team Link      12155    
#> 2 2020-11-22 19:29:36 FREE~ dropped   0009         Team Link      13794    
#> 3 2020-11-22 14:49:11 FREE~ added     0014         Team Luigi     14062    
#> 4 2020-11-21 22:24:25 IR    deactiva~ 0014         Team Luigi     13136    
#> 5 2020-11-21 22:24:02 FREE~ added     0014         Team Luigi     13136    
#> # ... with 886 more rows, and 6 more variables: player_name <chr>, pos <chr>,
#> #   team <chr>, bbid_spent <dbl>, trade_partner <chr>, comments <chr>

For a more detailed usage example, including a template dynasty league analysis script, please check out the reference articles and/or vignettes!

Contributing

Many hands make light work! Here are some ways you can contribute to this project:

Terms of Use

The R code for this package is released as open source under the MIT license.

The APIs and data accessed by this package belong to their respective owners, and are governed by their terms of use.