This package is designed to allow users to extract various world football results and player statistics from the following popular football (soccer) data sites:
You can install the worldfootballR
package from github with:
# install.packages("devtools")
::install_github("JaseZiv/worldfootballR") devtools
library(worldfootballR)
Package vignettes have been built to help you get started with the package.
This vignette will cover the functions to extract data from transfermarkt.com
To be able to join data player between FBref and Transfermarkt, player_dictionary_mapping()
has been created. There are over 6,100 players who have been listed for teams in the Big 5 Euro leagues on FBref since the start of the 2017-18 seasons, with all of these mapped together. This is expected to be updated and grow over time. The raw data is stored here
<- player_dictionary_mapping()
mapped_players ::glimpse(mapped_players)
dplyr#> Rows: 6,378
#> Columns: 4
#> $ PlayerFBref <chr> "Aaron Connolly", "Aaron Cresswell", "Aarón Escandell", "A…
#> $ UrlFBref <chr> "https://fbref.com/en/players/27c01749/Aaron-Connolly", "h…
#> $ UrlTmarkt <chr> "https://www.transfermarkt.com/aaron-connolly/profil/spiel…
#> $ TmPos <chr> "Centre-Forward", "Left-Back", "Goalkeeper", "Attacking Mi…
The following section will outline the various functions available to find different URLs to be able to pass through the Transfermarkt suite of functions outlined in this vignette.
To get a list of URLs for each team in a particular season from transfermarkt.com, the tm_league_team_urls()
function can be used. If the country/countries aren’t available in the main data set, the function can also accept a League URL from transfermarkt.com. To get the league URL, use the filtering options towards the top of transfermarkt.com, select the country and league you want to collect data from, head to that page, and copy the URL.
<- tm_league_team_urls(country_name = "England", start_year = 2020)
team_urls # if it's not a league in the stored leagues data in worldfootballR_data repo:
<- tm_league_team_urls(start_year = 2020, league_url = "https://www.transfermarkt.com/league-one/startseite/wettbewerb/GB3") league_one_teams
To get a list of player URLs for a particular team in transfermarkt.com, the tm_team_player_urls()
function can be used.
tm_team_player_urls(team_url = "https://www.transfermarkt.com/fc-burnley/startseite/verein/1132/saison_id/2020")
To get a list of staff URLs for a particular team(s) and staff role in transfermarkt.com, the tm_league_staff_urls()
function can be used.
The staff roles that can be passed to the function via the staff_role
argument are below:
# get a list of team URLs for the EPL 2021/22 season
<- tm_league_team_urls(country_name = "England", start_year = 2021)
epl_teams # get all EPL managers for the 2021/22 season
<- tm_team_staff_urls(team_urls = epl_teams, staff_role = "Manager")
epl_managers
# get all EPL goal keeping coaches for the 2021/22 season
<- tm_team_staff_urls(team_urls = epl_teams, staff_role = "Goalkeeping Coach") epl_gk_coaches
This section will cover the functions to aid in the extraction of season team statistics.
To be able to extract league tables for select matchday(s), the below function can be used.
The function can accept either the country name, season start year and matchday number(s), or for leagues not contained in the worldfootballR_data repository, it can accept the league URL, season start year and matchday number(s).
# to get the EPL table after matchday 1 of the 20/21 season:
<- tm_matchday_table(country_name="England", start_year="2020", matchday=1)
epl_matchday_1_table
# to get the EPL table after each matchdays from matchday 1 to matchday 35 of the 20/21 season:
<- tm_matchday_table(country_name="England", start_year="2020", matchday=c(1:35))
epl_matchday_1to35_table
# to get the EPL table after each matchdays from matchday 1 to matchday 35 of the 20/21 season:
<- tm_matchday_table(start_year="2020", matchday=1, league_url="https://www.transfermarkt.com/league-one/startseite/wettbewerb/GB3") league_one_matchday_1_table
This section will cover off the functions to get team-level data from Transfermarkt.
To get all the arrivals and departures for a team (or teams) in a season and data regarding the transfer (transfer value, contract length, where they came from/went to, etc), the tm_team_transfers()
function can be used. This function can return either summer
, winter
or all
for both transfer_windows
:
# for one team:
<- tm_team_transfers(team_url = "https://www.transfermarkt.com/fc-bayern-munchen/startseite/verein/27/saison_id/2020", transfer_window = "all")
bayern
# or for multiple teams:
<- tm_league_team_urls(country_name = "England", start_year = 2020)
team_urls <- tm_team_transfers(team_url = team_urls, transfer_window = "all") epl_xfers_2020
To get basic statistics (goals, appearances, minutes played, etc) for all games played by players for a squad season, the tm_squad_stats()
function can be used:
# for one team:
<- tm_squad_stats(team_url = "https://www.transfermarkt.com/fc-bayern-munchen/startseite/verein/27/saison_id/2020")
bayern
# or for multiple teams:
<- tm_league_team_urls(country_name = "England", start_year = 2020)
team_urls <- tm_squad_stats(team_url = team_urls) epl_team_players_2020
To get player valuations for all teams in a league season, use the get_player_market_values()
function:
<- get_player_market_values(country_name = c("England", "Spain", "France", "Italy", "Germany"),
big_5_valuations start_year = 2021)
This section will cover the functions available to aid in the extraction of player data.
To get information about a player, like their age, foot, where they were born, who they play for, their contract details, social media accounts and a whole lot more, use the tm_player_bio()
function.:
# for a single player
<- tm_player_bio(player_url = "https://www.transfermarkt.com/eden-hazard/profil/spieler/50202")
hazard_bio
# for multiple players:
# can make use of a tm helper function:
<- tm_team_player_urls(team_url = "https://www.transfermarkt.com/fc-burnley/startseite/verein/1132/saison_id/2020")
burnley_player_urls # then pass all those URLs to the tm_player_bio
<- tm_player_bio(player_urls = burnley_player_urls) burnley_bios
From version 0.4.7, users now have the ability to get historical data for club staff from transfermarkt.
The following two functions can be used, depending on the need (in addition to the helper function tm_team_staff_urls()
detailed above).
You can extract all employees by role in a club’s history using tm_team_staff_history()
.
The list of roles that can be passed to the staff_roles
argument can be found here
# get a list of team URLs for the EPL 2021/22 season
<- tm_league_team_urls(country_name = "England", start_year = 2021)
epl_teams
# then use the URLs to pass to the function, and select the role you wish to see results for
<- tm_team_staff_history(team_urls = epl_teams, staff_role = "Manager")
club_manager_history <- tm_team_staff_history(team_urls = epl_teams, staff_role = "Caretaker Manager") club_caretaker_manager_history
To be able to get all roles held by a selected staff member(s), the tm_staff_job_history()
function can be used.
The function accepts one argument, staff_urls
, which can be extracted using tm_team_staff_urls()
explained in the helpers section above.
# get a list of team URLs for the EPL 2021/22 season
<- tm_league_team_urls(country_name = "England", start_year = 2021)
epl_teams
# get all EPL goal keeping coaches for the 2021/22 season
<- tm_team_staff_urls(team_urls = epl_teams[1:3], staff_role = "Goalkeeping Coach")
epl_gk_coaches # then you can pass these URLs to the function and get job histories for the selected staff members
<- tm_staff_job_history(staff_urls = epl_gk_coaches) epl_gk_coach_job_histories