worldfootballR The Complete Guide for Soccer Data in R

worldfootballR: The Complete Guide for Soccer Data in R



worldfootballR: The Complete Guide for Soccer Data in R

worldfootballR is one of the most popular R packages for collecting and analyzing soccer data. Whether you are a data scientist, a football analyst, or just a fan who loves statistics, this package makes it simple to pull structured data from FBref, Transfermarkt, and Understat. With tidy outputs ready for analysis, you can focus on exploring tactics, player performance, and predictive models instead of manual scraping.

What is worldfootballR?

worldfootballR is an open-source package in R created to streamline the access of soccer data. It allows users to extract detailed statistics about teams, players, matches, transfers, and more. Instead of spending hours copying data, you can use a few lines of R code to collect everything you need for your analysis.

Installation

# Install from CRAN
install.packages("worldfootballR")

# Or install the development version from GitHub
devtools::install_github("JaseZiv/worldfootballR")

Supported Data Sources

  • FBref – advanced player and team stats, match logs, scouting reports.
  • Transfermarkt – transfers, squads, staff details, market values.
  • Understat – expected goals (xG), shooting locations, league and team data.

Example Workflows

FBref Example

library(worldfootballR)

# Get Premier League team stats for 2024/25 season
fb_stats <- fb_season_team_stats(
  country = "ENG",
  gender = "M",
  season_end_year = 2025,
  tier = "1st",
  stat_type = "shooting"
)
head(fb_stats)

Transfermarkt Example

# Get transfer history for Bayern Munich players
team_players <- tm_team_player_urls("https://www.transfermarkt.com/fc-bayern-munchen/startseite/verein/27")
transfers <- tm_player_transfer_history(player_urls = team_players)
head(transfers)

Understat Example

# Load shot locations for the Premier League 2024/25 season
epl_shots <- load_understat_league_shots(league = "EPL", season_start_year = 2024)
head(epl_shots)

Best Practices

  • Respect site rate limits – add pauses between requests.
  • Cache your data locally to avoid repeated scraping.
  • Always review Terms of Service of the data source.

Why Use worldfootballR?

The main advantage of worldfootballR is speed and consistency. Instead of manually scraping or downloading CSVs, you can access structured, ready-to-use data directly in R. This makes it perfect for:

  • Exploratory Data Analysis of soccer statistics
  • Machine learning models for match prediction
  • Player scouting and recruitment analysis
  • Tactical analysis and visualization

Learn More with Our Book

If you want to go beyond data collection and build complete analytics pipelines with R, check out our book: Mastering Sports Analytics with R: Insights from Soccer. This guide shows how to use advanced statistics, machine learning, and visualization to get real insights from soccer data.

Leave a Comment

Your email address will not be published. Required fields are marked *