Learn R Programming

⚠️There's a newer version (1.4.8) of this package.Take me there.

ffscrapr

An R Client for Fantasy Football League APIs

Helps access various Fantasy Football APIs (currently MFL, Sleeper, Fleaflicker, and ESPN - eventually 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.4.0 is now on CRAN :tada: and can be installed with:

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

Install the development version from GitHub with:

remotes::install_github("dynastyprocess/ffscrapr", ref = "dev")

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()
#> Using request.R from "ffscrapr"
#> No encoding supplied: defaulting to UTF-8.
#> 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: 443 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, Evan    TE    NYG    26.6
#> 2 0001         Team Pikachu   11680     Landry, Jarvis  WR    CLE    28.4
#> 3 0001         Team Pikachu   13645     Smith, Tre'Quan WR    NOS    25.3
#> 4 0001         Team Pikachu   12110     Brate, Cameron  TE    TBB    29.8
#> 5 0001         Team Pikachu   13168     Reynolds, Josh  WR    LAR    26.2
#> # ... with 438 more rows, and 4 more variables: roster_status <chr>,
#> #   drafted <chr>, draft_year <chr>, draft_round <chr>

# Get transactions
ff_transactions(ssb)
#> # A tibble: 152 x 12
#>   timestamp           type       type_desc franchise_id franchise_name   
#>   <dttm>              <chr>      <chr>     <chr>        <chr>            
#> 1 2020-07-09 17:25:20 FREE_AGENT dropped   0004         Team Ice Climbers
#> 2 2020-07-09 17:25:20 FREE_AGENT dropped   0004         Team Ice Climbers
#> 3 2020-06-16 01:56:49 TAXI       promoted  0014         Team Luigi       
#> 4 2020-06-16 01:56:49 TAXI       demoted   0014         Team Luigi       
#> 5 2020-06-12 23:51:44 FREE_AGENT dropped   0010         Team Yoshi       
#> # ... with 147 more rows, and 7 more variables: player_id <chr>,
#> #   player_name <chr>, pos <chr>, team <chr>, bbid_spent <dbl>,
#> #   trade_partner <chr>, comments <chr>

Platform-specific guides on getting started with ffscrapr are here:

There are also some more advanced guides for custom API calls in the Articles section, as well as some guides on optimizing ffscrapr’s performance.

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.

Copy Link

Version

Install

install.packages('ffscrapr')

Monthly Downloads

531

Version

1.4.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Tan Ho

Last Published

April 13th, 2021

Functions in ffscrapr (1.4.0)

dp_playerids

Import latest DynastyProcess player IDs
espn_getendpoint

GET ESPN fantasy league endpoint
espn_connect

Connect to ESPN League
fleaflicker_connect

Connect to Fleaflicker League
.fn_set_useragent

Set user agent
espn_getendpoint_raw

GET ESPN endpoint (raw)
espn_players

ESPN players library
.sleeper_userid

Get Sleeper User ID
.espn_pos_map

ESPN Primary Position map
.mfl_logincookie

Get MFL Login Cookie
ffscrapr-package

ffscrapr: API Client for Fantasy Football League Platforms
fleaflicker_userleagues

Fleaflicker - Get User Leagues
dp_values

Import latest DynastyProcess values
.retry_get

Create RETRY version of GET
mfl_allrules

MFL rules library - memoised via zzz.R
ff_schedule

Get Schedule
ff_scoring

Get League Scoring Settings
dp_cleannames

Clean Names
ff_rosters

Get League Rosters
ff_starters

Get Starting Lineups
ff_playerscores

Get Player Scoring History
ff_starter_positions

Get Starting Lineup Settings
espn_potentialpoints

ESPN Potential Points
ff_connect

Connect to a League
nflfastr_weekly

Import latest nflfastr weekly stats
sleeper_connect

Connect to Sleeper League
fleaflicker_players

Fleaflicker players library
fleaflicker_getendpoint

GET any Fleaflicker endpoint
parse_raw_rds

Parse Raw RDS
ff_franchises

Get League Franchises
.retry_post

Create RETRY version of POST
sleeper_players

Sleeper players library
ff_draftpicks

Get Draft Picks
ff_userleagues

Get User Leagues
ff_draft

Get Draft Results
ff_transactions

Get League Transactions
mfl_connect

Connect to MFL League
mfl_getendpoint

GET any MFL endpoint
ff_scoringhistory

Get League-Specific Scoring History
mfl_players

MFL players library
%>%

Pipe operator
nflfastr_rosters

Import nflfastr roster data
ff_league

Get League Summary
ff_standings

Get Standings
set_unescaped_cookies

Add unescaped cookies
sleeper_userleagues

Sleeper - Get User Leagues
sleeper_getendpoint

GET any Sleeper endpoint
.espn_team_map

ESPN Team ID map
.ff_clear_cache

Empty Function Cache
.fn_choose_season

Choose current season
.espn_activity_map

ESPN Activity/Transaction Mapping
.fn_set_ratelimit

Set rate limit
.espn_stat_map

ESPN Stat ID map
.fn_drop_nulls

Drop nulls from a list/vector
.add_allplay

Add allplay from a standardised schedule output
.espn_lineupslot_map

ESPN Lineup Slot map