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 for international matches from FBref.com.
The functions in this document are all documented in the FBref data vignette, however the method for using these functions for international matches differs from those played in domestic leagues.
To get the competition URLs needed for a lot of the functions in this document, refer to the column comp_url
for the relevant league / competition you’re interested in, in this stored data file.
To get the match URLs needed to pass in to some of the match-level functions below, get_match_urls()
can be used.
<- get_match_urls(country = "", gender = "M", season_end_year = 2018, tier = "", non_dom_league_url = "https://fbref.com/en/comps/1/history/World-Cup-Seasons")
wc_2018_urls
<- get_match_urls(country = "", gender = "M", season_end_year = 2021, tier = "", non_dom_league_url = "https://fbref.com/en/comps/218/history/Friendlies-M-Seasons")
friendly_int_2021_urls
<- get_match_urls(country = "", gender = "M", season_end_year = 2021, tier = "", non_dom_league_url = "https://fbref.com/en/comps/676/history/European-Championship-Seasons")
euro_2021_urls
<- get_match_urls(country = "", gender = "M", season_end_year = 2019, tier = "", non_dom_league_url = "https://fbref.com/en/comps/685/history/Copa-America-Seasons") copa_2019_urls
The following sections outlines the functions available to extract data at the per-match level
To get the match results (and additional metadata), the following function can be used.
To use this functionality, simply leave country = ''
and pass the non-domestic league URL
# euro 2016 results
<- get_match_results(country = "", gender = "M", season_end_year = 2016, tier = "", non_dom_league_url = "https://fbref.com/en/comps/676/history/European-Championship-Seasons")
euro_2016_results
# 2019 Copa America results:
<- get_match_results(country = "", gender = "M", season_end_year = 2019, non_dom_league_url = "https://fbref.com/en/comps/685/history/Copa-America-Seasons")
copa_2019_results
# for international friendlies:
<- get_match_results(country = "", gender = "M", season_end_year = 2021, tier = "", non_dom_league_url = "https://fbref.com/en/comps/218/history/Friendlies-M-Seasons") international_results
This function will return similar results to that of get_match_results()
, however get_match_report()
will provide some additional information. It will also only provide it for a single match, not the whole season:
# function to extract match report data for 2018 world cup
<- get_match_report(match_url = wc_2018_urls)
wc_2018_report # function to extract match report data for 2021 international friendlies
<- get_match_report(match_url = friendly_int_2021_urls) friendlies_report
This function will return the main events that occur during a match, including goals, substitutions and red/yellow cards:
# first get the URLs for the 2016 Euros
<- get_match_urls(country = "", gender = "M", season_end_year = 2016, tier = "", non_dom_league_url = "https://fbref.com/en/comps/676/history/European-Championship-Seasons")
euro_2016_match_urls
# then pass these to the function to get match summaries:
<- get_match_summary(euro_2016_match_urls) euro_2016_events
This function will return a dataframe of all players listed for that match, including whether they started on the pitch, or on the bench.
From version 0.2.7, this function now also returns some summary performance data for each player that played, including their position, minutes played, goals, cards, etc.
# function to extract match lineups
<- get_match_lineups(match_url = copa_2019_urls) copa_2019_lineups
The below function allows users to extract shooting and shot creation event data for a match or selected matches. The data returned includes who took the shot, when, with which body part and from how far away. Additionally, the player creating the chance and also the creation before this are included in the data.
<- get_match_shooting(wc_2018_urls) shots_wc_2018
The get_advanced_match_stats()
function allows the user to return a data frame of different stat types for matches played.
Note, some stats may not be available for all comps.
The following stat types can be selected:
The function can be used for either all players individually:
<- get_advanced_match_stats(match_url = wc_2018_urls, stat_type = "possession", team_or_player = "player") advanced_match_stats_player
Or used for the team totals for each match:
<- get_advanced_match_stats(match_url = wc_2018_urls, stat_type = "passing_types", team_or_player = "team") advanced_match_stats_team