The stable datasets in the package will become out of date as and when users interact with fantasy.premierleague.com, they became out of date almost immediately after the package was created (sigh). The function collect_ff
allows for up-to-date data to be collected by accessing the ‘official’ API, the function should be used sparingly. (This post was written 2016-04-20 22:01:14)
The collect_ff
function needn’t take any arguments, by default it will attempt to collect data for 600 players, this is time-consuming so I won’t do that in this post, instead I will collect just 25 players. The .progress
argument is from the plyr package and will tell the user roughly how much longer it will take to complete the collecting (“text” or “time” are most useful imo)
new_data <- collect_ff(n = 25)
A new list of length 25, each list element is one player and contains the following data:
id, photo, web_name, event_explain, fixture_history, season_history, fixtures, event_total, type_name, team_name, selected_by, total_points, current_fixture, next_fixture, team_code, news, team_id, status, code, first_name, second_name, now_cost, chance_of_playing_this_round, chance_of_playing_next_round, value_form, value_season, cost_change_start, cost_change_event, cost_change_start_fall, cost_change_event_fall, in_dreamteam, dreamteam_count, selected_by_percent, form, transfers_out, transfers_in, transfers_out_event, transfers_in_event, loans_in, loans_out, loaned_in, loaned_out, event_points, points_per_game, ep_this, ep_next, special, minutes, goals_scored, assists, clean_sheets, goals_conceded, own_goals, penalties_saved, penalties_missed, yellow_cards, red_cards, saves, bonus, ea_index, bps, element_type, team
Not all of the data for each player is particularly valuable, such as photo. However we can extract the data found in the players, pastseasons datasets. The code below shows how:
new_players_df <- players_df(new_data)
dim(new_players_df)
## [1] 25 7
The pastseasons dataset won’t change much, however that dataset also contains data about the current players such as value, team and percentage of teams the player is selected in.
new_pastseasons_df <- pastseasons_df(new_data)
dim(new_pastseasons_df)
## [1] 121 24
There is one function, currentseason_df
, that may be more interesting, it creates a dataframe, similar to that of pastseasons, but it records the performance of every player in every gameweek so far in the current season.
currentseason <- currentseason_df(new_data)
str(currentseason)
## 'data.frame': 950 obs. of 27 variables:
## $ id : num 1 1 1 1 1 1 1 1 1 1 ...
## $ name : chr "Szczesny" "Szczesny" "Szczesny" "Szczesny" ...
## $ pos : chr "Goalkeeper" "Goalkeeper" "Goalkeeper" "Goalkeeper" ...
## $ team : chr "Arsenal" "Arsenal" "Arsenal" "Arsenal" ...
## $ pts : num 47 47 47 47 47 47 47 47 47 47 ...
## $ value : num 5.2 5.2 5.2 5.2 5.2 5.2 5.2 5.2 5.2 5.2 ...
## $ pct : num 4.7 4.7 4.7 4.7 4.7 4.7 4.7 4.7 4.7 4.7 ...
## $ date : chr "16 Aug 17:30" "23 Aug 17:30" "31 Aug 16:00" "13 Sep 12:45" ...
## $ gw : num 1 2 3 4 5 6 7 8 9 10 ...
## $ opp : chr "CRY(H) 2-1" "EVE(A) 2-2" "LEI(A) 1-1" "MCI(H) 2-2" ...
## $ mins : num 90 90 90 90 90 90 90 90 90 90 ...
## $ goals : num 0 0 0 0 0 0 0 0 0 0 ...
## $ assists : num 0 0 0 0 0 0 0 0 0 0 ...
## $ cs : num 0 0 0 0 1 0 0 0 1 1 ...
## $ ga : num 1 2 1 2 0 1 2 2 0 0 ...
## $ og : num 0 0 0 0 0 0 0 0 0 0 ...
## $ pens_svd : num 0 0 0 0 0 0 0 0 0 0 ...
## $ pens_msd : num 0 0 0 0 0 0 0 0 0 0 ...
## $ yel : num 0 0 1 0 0 0 0 0 0 0 ...
## $ red : num 0 0 0 0 0 0 0 0 0 0 ...
## $ saves : num 1 0 2 6 2 4 1 2 3 2 ...
## $ bonus : num 0 0 0 0 0 0 0 0 0 0 ...
## $ ea_ppi : num 13 5 7 12 14 10 3 7 16 14 ...
## $ bps : num 7 9 15 17 22 13 9 9 22 24 ...
## $ net_transfers: num 0 -9306 -20971 -39686 -15931 ...
## $ gw_val : num 5.5 5.5 5.5 5.5 5.5 5.5 5.5 5.4 5.4 5.4 ...
## $ gw_pts : num 2 1 1 3 6 3 1 1 7 6 ...