This vignette is an introduction to the principles and functions of the fplr
package. Note that functions that are dependent on the season being live are not actually evaluated.
Fantasy Premier League (FPL) is the official fantasy football game of the Premier League, the top competitive football division in England. FPL players compete to score the most points come the end of the season (following these rules).
fplr
is an R package that houses tools for working with FPL data in R. This toolset mostly consists of functions to help with FPL managers’ (referred to herein as users), players’, teams’ and fixtures data, for current and previous seasons of the game.
N.B. The package mostly retrieves this data from endpoints across the FPL site (for example, the bootstrap-static endpoint). At time of writing, there is no formal developer support, and so any sudden game alterations that affect the data structure may cause functionality in this package to break. File any issues over at the Github repo issue tracker.
Functions in the player data family primarily return information about players in the game, and are mostly for exploring data in the current season (note - when a new season of the game begins, old season data returned from these functions will be overwritten).
These functions follow the naming convention fpl_get_player_xxx
. For example, fpl_get_player_all()
returns data for all players in the current season, via a tidy tibble:
fpl_get_player_all()
# # A tibble: 529 x 53
# chance_of_playi… chance_of_playi… code cost_change_eve…
# <int> <int> <int> <dbl>
# 1 NA NA 69140 -0.1
# 2 0 0 98745 0
# 3 100 75 111457 0
# 4 NA NA 154043 0
# 5 NA NA 39476 0
# 6 NA NA 38411 0
# 7 0 0 51507 0
# 8 0 0 233963 -0.1
# 9 0 0 80254 0
# 10 0 0 156074 0
# # … with 519 more rows, and 49 more variables:
# # cost_change_event_fall <int>, cost_change_start <dbl>,
# # cost_change_start_fall <int>, dreamteam_count <int>,
# # element_type <int>, ep_next <dbl>, ep_this <dbl>, event_points <int>,
# # first_name <chr>, form <dbl>, id <int>, in_dreamteam <lgl>,
# # news <chr>, news_added <chr>, now_cost <dbl>, photo <chr>,
# # points_per_game <dbl>, second_name <chr>, selected_by_percent <dbl>,
# # special <lgl>, squad_number <lgl>, status <chr>, team <int>,
# # team_code <int>, total_points <int>, transfers_in <int>,
# # transfers_in_event <int>, transfers_out <int>,
# # transfers_out_event <int>, value_form <dbl>, value_season <dbl>,
# # web_name <chr>, minutes <int>, goals_scored <int>, assists <int>,
# # clean_sheets <int>, goals_conceded <int>, own_goals <int>,
# # penalties_saved <int>, penalties_missed <int>, yellow_cards <int>,
# # red_cards <int>, saves <int>, bonus <int>, bps <int>, influence <dbl>,
# # creativity <dbl>, threat <dbl>, ict_index <dbl>
Get gameweek-level data for a single player in the current season, using fpl_get_player_current()
(supplying a player_id
value, possibly gleaned from the fpl_get_player_all()
output):
You can even get historic seasons’ data (if it exists) for a player, using fpl_get_player_historic
:
fpl_get_player_historic(player_id = 3)
# # A tibble: 2 x 22
# season_name element_code start_cost end_cost total_points minutes
# <chr> <int> <dbl> <dbl> <int> <int>
# 1 2017/18 111457 6 5.8 108 2146
# 2 2018/19 111457 5 4.9 81 1886
# # … with 16 more variables: goals_scored <int>, assists <int>,
# # clean_sheets <int>, goals_conceded <int>, own_goals <int>,
# # penalties_saved <int>, penalties_missed <int>, yellow_cards <int>,
# # red_cards <int>, saves <int>, bonus <int>, bps <int>, influence <chr>,
# # creativity <chr>, threat <chr>, ict_index <chr>
Functions in the user data family primarily return information about users, and like the players functions already covered, are mostly for exploring data in the current season (again - when a new season of the game begins, data from these functions may be overwritten).
These functions follow the naming convention fpl_get_user_xxx
. Get information on current season performance of a user by supplying the corresponding user_id
(taken from the main FPL website) to the fpl_get_user_current()
function:
Or, get historic seasons performance using fpl_get_user_history()
:
These functions follow the naming convention fpl_get_teams_xxx
.
Summary data for teams in the current FPL season is gleaned using fpl_get_teams()
:
fpl_get_teams()
# # A tibble: 20 x 20
# code draw form id loss name played points position short_name
# <int> <int> <lgl> <int> <int> <chr> <int> <int> <int> <chr>
# 1 3 0 NA 1 0 Arse… 0 0 0 ARS
# 2 7 0 NA 2 0 Asto… 0 0 0 AVL
# 3 91 0 NA 3 0 Bour… 0 0 0 BOU
# 4 36 0 NA 4 0 Brig… 0 0 0 BHA
# 5 90 0 NA 5 0 Burn… 0 0 0 BUR
# 6 8 0 NA 6 0 Chel… 0 0 0 CHE
# 7 31 0 NA 7 0 Crys… 0 0 0 CRY
# 8 11 0 NA 8 0 Ever… 0 0 0 EVE
# 9 13 0 NA 9 0 Leic… 0 0 0 LEI
# 10 14 0 NA 10 0 Live… 0 0 0 LIV
# 11 43 0 NA 11 0 Man … 0 0 0 MCI
# 12 1 0 NA 12 0 Man … 0 0 0 MUN
# 13 4 0 NA 13 0 Newc… 0 0 0 NEW
# 14 45 0 NA 14 0 Norw… 0 0 0 NOR
# 15 49 0 NA 15 0 Shef… 0 0 0 SHU
# 16 20 0 NA 16 0 Sout… 0 0 0 SOU
# 17 6 0 NA 17 0 Spurs 0 0 0 TOT
# 18 57 0 NA 18 0 Watf… 0 0 0 WAT
# 19 21 0 NA 19 0 West… 0 0 0 WHU
# 20 39 0 NA 20 0 Wolv… 0 0 0 WOL
# # … with 10 more variables: strength <int>, team_division <lgl>,
# # unavailable <lgl>, win <int>, strength_overall_home <int>,
# # strength_overall_away <int>, strength_attack_home <int>,
# # strength_attack_away <int>, strength_defence_home <int>,
# # strength_defence_away <int>
These functions follow the naming convention fpl_get_fixtures_xxx
.
Summary data for teams in the current FPL season is gleaned using fpl_get_fixtures()
:
fpl_get_fixtures()
# # A tibble: 380 x 16
# code event finished finished_provis… id kickoff_time minutes
# <int> <int> <lgl> <lgl> <int> <dttm> <int>
# 1 1.06e6 1 TRUE TRUE 1 2019-08-09 00:00:00 90
# 2 1.06e6 1 TRUE TRUE 8 2019-08-10 00:00:00 90
# 3 1.06e6 1 TRUE TRUE 2 2019-08-10 00:00:00 90
# 4 1.06e6 1 TRUE TRUE 3 2019-08-10 00:00:00 90
# 5 1.06e6 1 TRUE TRUE 4 2019-08-10 00:00:00 90
# 6 1.06e6 1 TRUE TRUE 7 2019-08-10 00:00:00 90
# 7 1.06e6 1 TRUE TRUE 6 2019-08-10 00:00:00 90
# 8 1.06e6 1 TRUE TRUE 5 2019-08-11 00:00:00 90
# 9 1.06e6 1 TRUE TRUE 10 2019-08-11 00:00:00 90
# 10 1.06e6 1 TRUE TRUE 9 2019-08-11 00:00:00 90
# # … with 370 more rows, and 9 more variables:
# # provisional_start_time <lgl>, started <lgl>, team_a <int>,
# # team_a_score <int>, team_h <int>, team_h_score <int>, stats <list>,
# # team_h_difficulty <int>, team_a_difficulty <int>