Functions for retrieving player and manager scores from the Fantasy Premier League API for the current season.
Note: there are many more functions available in the better-maintained fplscrapR package.
You can install soccermatics from GitHub in R using devtools:
if (!require("devtools")) install.packages("devtools")
devtools::install_github("wiscostret/fplscrapR") #dependency
devtools::install_github("jogall/fantasypl")
To avoid confusion, 'player' here refers to football players (e.g. Salah) and 'manager' refers to FantasyPL teams (e.g. I'm manager of the glorious Birkenhead Albion).
# load package and
library(fantasypl)
library(dplyr)
Get total points and other statistics for all players:
player_points()
Get points and other statistics for all players in each gameweek (note this function can take a while as the API must be called 559 times):
player_points_by_gw()
Get total points for specified managers.
e.g. Total points for team IDs 1
, 2
:
manager_points(c(1, 2))
Get players picked by managers of specified teams and in specified gameweeks.
e.g. Picks for team IDs 1
, 2
in gameweeks 11, 12:
manager_picks(c(1, 2), 11:12)
TODO: add player name to returned information.
Calculate expected points (xPts) and expected rank (xRank) for each team in a head-to-head league as the average number of points (i.e. 0, 1, 3) expected against all teams in that league each gameweek (including AVERAGE team, present if odd number of teams in the league), not just the actual opponent.
Requires entering username and password in interactive dialogue in order to access private leagues, using the fplscrapR
package.
e.g. xPts for league ID 1
.
xpts_h2h(1)
get_fixtures() %>%
filter(finished = T)
get_fixtures() %>%
filter(finished = T)