diff --git a/DESCRIPTION b/DESCRIPTION index b48f513e..e1d22da1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: worldfootballR Title: Functions to Extract and Clean World Football (Soccer) Data -Version: 0.5.2.3000 +Version: 0.5.3 Authors@R: c( person("Jason", "Zivkovic", , "jaseziv83@gmail.com", role = c("aut", "cre", "cph")), person("Tony", "ElHabr", , "anthonyelhabr@gmail.com", role = "ctb") @@ -40,7 +40,8 @@ Imports: utils, withr, xml2, - tibble + tibble, + cli Suggests: knitr, rmarkdown, diff --git a/NAMESPACE b/NAMESPACE index ff38c449..78d97188 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,6 +27,8 @@ export(get_match_urls) export(get_player_market_values) export(get_season_team_stats) export(get_team_match_results) +export(load_fb_big5_advanced_season_stats) +export(load_match_results) export(player_dictionary_mapping) export(player_transfer_history) export(tm_expiring_contracts) diff --git a/NEWS.md b/NEWS.md index ce44637d..af0cea76 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,14 @@ +# worldfootballR 0.5.3 + +### Improvements + +Now starting to have load functions: + +* `load_match_results()` - function to load pre stored data similar to `get_match_results()` +* `load_fb_big5_advanced_season_stats()` - function to load pre stored data similar to `fb_big5_advanced_season_stats()` + +*** + # worldfootballR 0.5.2.3000 ### Bugs diff --git a/R/fotmob_stats.R b/R/fotmob_stats.R index fef83be3..edf861f9 100644 --- a/R/fotmob_stats.R +++ b/R/fotmob_stats.R @@ -91,7 +91,9 @@ #' @param team_or_player return statistics for either \code{"team"} or \code{"player"}. Can only be one or the other. #' @param stat_name the type of statistic. Can be more than one. #' `stat_name` must be one of the following for \code{"player"}: -#' \item{Accurate long balls per 90} +#' +#' \itemize{ +#' #' \item{Accurate long balls per 90} #' \item{Accurate passes per 90} #' \item{Assists} #' \item{Big chances created} @@ -126,7 +128,7 @@ #' \item{xG + xA per 90} #' \item{Yellow cards} #' } -#' +#' #' For \code{"team"}, `stat_name` must be one of the following: #' \itemize{ #' \item{Accurate crosses per match} @@ -175,20 +177,6 @@ #' team_or_player = "team" #' ) #' -#' ## fotmob doesn't has data for 2016/2017 for some leagues, but not all. -#' ## you'll see a warning about this and receive an empty dataframe -#' get_epl_season_stats( -#' season = "2016/2017" -#' ) -#' -#' ## Note that the `stat_type` name is slightly different. -#' epl_player_xg_2021 <- get_epl_season_stats( -#' country = "ENG", -#' league_name = "Premier League", -#' season = "2020/2021", -#' stat_type = "Expected goals (xG)", -#' team_or_player = "player" -#' ) #' } fotmob_get_season_stats <- function( country, diff --git a/R/internals_loading.R b/R/internals_loading.R new file mode 100644 index 00000000..e8763709 --- /dev/null +++ b/R/internals_loading.R @@ -0,0 +1,14 @@ +#' Read in stored RDS data +#' +#' Reads in RDS stored data files typically stored on GitHub +#' +#' @param file_url URL to RDS file(s) for reading in +#' +#' @return data type dependent on RDS file being read in +#' +#' + +.file_reader <- function(file_url) { + tryCatch(readRDS(url(file_url)), error = function(e) data.frame()) %>% + suppressWarnings() +} diff --git a/R/load_fb.R b/R/load_fb.R new file mode 100644 index 00000000..5c844f4c --- /dev/null +++ b/R/load_fb.R @@ -0,0 +1,111 @@ +#' Load match results +#' +#' Loading version of \code{get_match_results} +#' Returns the game results for a given league season(s) from FBref +#' +#' @param country the three character country code +#' @param gender gender of competition, either "M" or "F" +#' @param season_end_year the year(s) the season concludes +#' @param tier the tier of the league, ie '1st' for the EPL or '2nd' for the Championship and so on +#' +#' @return returns a dataframe with the results of the competition, season and gender +#' +#' @importFrom magrittr %>% +#' @importFrom rlang .data +#' @importFrom utils read.csv +#' +#' @export +#' +#' @examples +#' \donttest{ +#' df <- load_match_results( +#' country = c("ITA"), gender = "M", season_end_year = 2021, tier = "1st" +#' ) +#' # for results from English 1st div for men and women: +#' df <- load_match_results( +#' country = "ENG", gender = c("M", "F"), season_end_year = 2021, tier = "1st" +#' ) +#' +#' } + +load_match_results <- function(country, gender, season_end_year, tier) { + dat_urls <- paste0("https://github.com/JaseZiv/worldfootballR_data/blob/master/data/match_results/", country, "_match_results.rds?raw=true") + + # collect_date <- .file_reader("https://github.com/JaseZiv/worldfootballR_data/blob/master/data/match_results/scrape_time_match_results.rds?raw=true") + dat_df <- dat_urls %>% purrr::map_df(.file_reader) + + if(nrow(dat_df) == 0) { + cli::cli_alert("Data not loaded. Please check parameters") + } else { + dat_df <- dat_df %>% + dplyr::filter(.data$Country %in% country, + .data$Gender %in% gender, + .data$Season_End_Year %in% season_end_year, + .data$Tier %in% tier) %>% + dplyr::select(-.data$Tier) + + cli::cli_alert("Data last updated {attr(dat_df, 'scrape_timestamp')} UTC") + } + + return(dat_df) + +} + + + +#' Load Big 5 Euro League Season Stats +#' +#' Loading version of \code{fb_big5_advanced_season_stats} +#' Returns data frame of selected statistics for seasons of the big 5 Euro leagues, for either +#' whole team or individual players. +#' Multiple seasons can be passed to the function, but only one `stat_type` can be selected +#' +#' @param season_end_year the year(s) the season concludes +#' @param stat_type the type of team statistics the user requires +#' @param team_or_player result either summarised for each team, or individual players +#' +#' The statistic type options (stat_type) include: +#' +#' \emph{"standard"}, \emph{"shooting"}, \emph{"passing"}, \emph{"passing_types"}, +#' \emph{"gca"}, \emph{"defense"}, \emph{"possession"}, \emph{"playing_time"}, +#' \emph{"misc"}, \emph{"keepers"}, \emph{"keepers_adv"} +#' +#' @return returns a dataframe of a selected team or player statistic type for a selected season(s) +#' +#' @importFrom magrittr %>% +#' @importFrom rlang .data +#' +#' @export +#' +#' @examples +#' \dontrun{ +#' +#' df <- load_fb_big5_advanced_season_stats( +#' season_end_year = c(2018:2022), stat_type = "defense", team_or_player = "player" +#' ) +#' +#' df <- load_fb_big5_advanced_season_stats( +#' season_end_year = 2022, stat_type = "defense", team_or_player = "player" +#' ) +#' } + +load_fb_big5_advanced_season_stats <- function(season_end_year = NA, stat_type, team_or_player) { + + dat_url <- paste0("https://github.com/JaseZiv/worldfootballR_data/blob/master/data/fb_big5_advanced_season_stats/big5_", team_or_player, "_", stat_type, ".rds?raw=true") + # collect_date <- .file_reader("https://github.com/JaseZiv/worldfootballR_data/blob/master/data/fb_big5_advanced_season_stats/scrape_time_big5_advanced_season_stats.rds?raw=true") + + dat_df <- tryCatch(.file_reader(dat_url), error = function(e) data.frame()) + + if(nrow(dat_df) == 0) { + cli::cli_alert("Data not available. Check you have the correct stat_type or team_or_player") + } else { + dat_df <- dat_df %>% + dplyr::filter(.data$Season_End_Year %in% season_end_year) + + cli::cli_alert("Data last updated {attr(dat_df, 'scrape_timestamp')} UTC") + } + + return(dat_df) + +} + diff --git a/man/dot-file_reader.Rd b/man/dot-file_reader.Rd new file mode 100644 index 00000000..a7e59bf0 --- /dev/null +++ b/man/dot-file_reader.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/internals_loading.R +\name{.file_reader} +\alias{.file_reader} +\title{Read in stored RDS data} +\usage{ +.file_reader(file_url) +} +\arguments{ +\item{file_url}{URL to RDS file(s) for reading in} +} +\value{ +data type dependent on RDS file being read in +} +\description{ +Reads in RDS stored data files typically stored on GitHub +} diff --git a/man/fotmob_get_season_stats.Rd b/man/fotmob_get_season_stats.Rd index a3c01ad3..ec317242 100644 --- a/man/fotmob_get_season_stats.Rd +++ b/man/fotmob_get_season_stats.Rd @@ -27,44 +27,46 @@ fotmob_get_season_stats( \item{team_or_player}{return statistics for either \code{"team"} or \code{"player"}. Can only be one or the other.} \item{stat_name}{the type of statistic. Can be more than one. -\code{stat_name} must be one of the following for \code{"player"}: +`stat_name` must be one of the following for \code{"player"}: + \itemize{ -\item{"Accurate long balls per 90"} -\item{"Accurate passes per 90"} -\item{"Assists} -\item{"Big chances created"} -\item{"Big chances missed"} -\item{"Blocks per 90"} -\item{"Chances created} -\item{"Clean sheets"} -\item{"Clearances per 90"} -\item{"Expected assist (xA)"} -\item{"Expected assist (xA) per 90"} -\item{"Expected goals (xG)"} -\item{"Expected goals (xG) per 90"} -\item{"Expected goals on target (xGOT)"} -\item{"FotMob rating"} -\item{"Fouls committed per 90"} -\item{"Goals + Assists"} -\item{"Goals conceded per 90"} -\item{"Goals per 90"} -\item{"Goals prevented"} -\item{"Interceptions per 90"} -\item{"Penalties conceded"} -\item{"Penalties won"} -\item{"Possession won final 3rd per 90"} -\item{"Red cards"} -\item{"Saves per 90"} -\item{"Shots on target per 90"} -\item{"Shots per 90"} -\item{"Successful dribbles per 90"} -\item{"Successful tackles per 90"} -\item{"Top scorer"} -\item{"xG + xA per 90"} -\item{"Yellow cards"} +#' \item{Accurate long balls per 90} +\item{Accurate passes per 90} +\item{Assists} +\item{Big chances created} +\item{Big chances missed} +\item{Blocks per 90} +\item{Chances created} +\item{Clean sheets} +\item{Clearances per 90} +\item{Expected assist (xA)} +\item{Expected assist (xA) per 90} +\item{Expected goals (xG)} +\item{Expected goals (xG) per 90} +\item{Expected goals on target (xGOT)} +\item{FotMob rating} +\item{Fouls committed per 90} +\item{Goals + Assists} +\item{Goals conceded per 90} +\item{Goals per 90} +\item{Goals prevented} +\item{Interceptions per 90} +\item{Penalties conceded} +\item{Penalties won} +\item{Possession won final 3rd per 90} +\item{Red cards} +\item{Save percentage} +\item{Saves per 90} +\item{Shots on target per 90} +\item{Shots per 90} +\item{Successful dribbles per 90} +\item{Successful tackles per 90} +\item{Top scorer} +\item{xG + xA per 90} +\item{Yellow cards} } -For `"team"`, `stat_name` must be one of the following: +For \code{"team"}, `stat_name` must be one of the following: \itemize{ \item{Accurate crosses per match} \item{Accurate long balls per match} @@ -115,19 +117,5 @@ epl_team_xg_2021 <- fotmob_get_season_stats( team_or_player = "team" ) -## fotmob doesn't has data for 2016/2017 for some leagues, but not all. -## you'll see a warning about this and receive an empty dataframe -get_epl_season_stats( - season = "2016/2017" -) - -## Note that the `stat_type` name is slightly different. -epl_player_xg_2021 <- get_epl_season_stats( - country = "ENG", - league_name = "Premier League", - season = "2020/2021", - stat_type = "Expected goals (xG)", - team_or_player = "player" -) } } diff --git a/man/load_fb_big5_advanced_season_stats.Rd b/man/load_fb_big5_advanced_season_stats.Rd new file mode 100644 index 00000000..e5e893b8 --- /dev/null +++ b/man/load_fb_big5_advanced_season_stats.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/load_fb.R +\name{load_fb_big5_advanced_season_stats} +\alias{load_fb_big5_advanced_season_stats} +\title{Load Big 5 Euro League Season Stats} +\usage{ +load_fb_big5_advanced_season_stats( + season_end_year = NA, + stat_type, + team_or_player +) +} +\arguments{ +\item{season_end_year}{the year(s) the season concludes} + +\item{stat_type}{the type of team statistics the user requires} + +\item{team_or_player}{result either summarised for each team, or individual players + +The statistic type options (stat_type) include: + +\emph{"standard"}, \emph{"shooting"}, \emph{"passing"}, \emph{"passing_types"}, +\emph{"gca"}, \emph{"defense"}, \emph{"possession"}, \emph{"playing_time"}, +\emph{"misc"}, \emph{"keepers"}, \emph{"keepers_adv"}} +} +\value{ +returns a dataframe of a selected team or player statistic type for a selected season(s) +} +\description{ +Loading version of \code{fb_big5_advanced_season_stats} +Returns data frame of selected statistics for seasons of the big 5 Euro leagues, for either +whole team or individual players. +Multiple seasons can be passed to the function, but only one `stat_type` can be selected +} +\examples{ +\dontrun{ + +df <- load_fb_big5_advanced_season_stats( +season_end_year = c(2018:2022), stat_type = "defense", team_or_player = "player" +) + +df <- load_fb_big5_advanced_season_stats( +season_end_year = 2022, stat_type = "defense", team_or_player = "player" +) +} +} diff --git a/man/load_match_results.Rd b/man/load_match_results.Rd new file mode 100644 index 00000000..110ce313 --- /dev/null +++ b/man/load_match_results.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/load_fb.R +\name{load_match_results} +\alias{load_match_results} +\title{Load match results} +\usage{ +load_match_results(country, gender, season_end_year, tier) +} +\arguments{ +\item{country}{the three character country code} + +\item{gender}{gender of competition, either "M" or "F"} + +\item{season_end_year}{the year(s) the season concludes} + +\item{tier}{the tier of the league, ie '1st' for the EPL or '2nd' for the Championship and so on} +} +\value{ +returns a dataframe with the results of the competition, season and gender +} +\description{ +Loading version of \code{get_match_results} +Returns the game results for a given league season(s) from FBref +} +\examples{ +\donttest{ +df <- load_match_results( +country = c("ITA"), gender = "M", season_end_year = 2021, tier = "1st" +) +# for results from English 1st div for men and women: +df <- load_match_results( +country = "ENG", gender = c("M", "F"), season_end_year = 2021, tier = "1st" +) + +} +} diff --git a/tests/testthat/test-load-fbref.R b/tests/testthat/test-load-fbref.R new file mode 100644 index 00000000..c19bcc82 --- /dev/null +++ b/tests/testthat/test-load-fbref.R @@ -0,0 +1,38 @@ +context("Testing FBref Load data functions") + + +test_that("load_match_results() works", { + testthat::skip_on_cran() + testthat::skip_if_offline() + test_df <- load_match_results(country = "ENG", gender = "M", season_end_year = 2022, tier="1st") + # test the functions returns the data + expect_type(test_df, "list") + + # test that multiple countries can be passed to the function + test_df <- load_match_results(country = c("ENG", "AUS"), gender = "F", season_end_year = 2021, tier="1st") + expect_type(test_df, "list") + expect_false(nrow(test_df) == 0) + + bad_df <- load_match_results(country = "foo", gender = "M", season_end_year = 2022, tier="1st") + expect_true(nrow(bad_df) == 0) + +}) + + +test_that("load_fb_big5_advanced_season_stats() works", { + testthat::skip_on_cran() + big5_team_shooting_multiple <- load_fb_big5_advanced_season_stats(season_end_year= c(2019:2021), stat_type= "shooting", team_or_player= "team") + expect_type(big5_team_shooting_multiple, "list") + expect_false(nrow(big5_team_shooting_multiple) == 0) + + big5_team_shooting <- load_fb_big5_advanced_season_stats(season_end_year= c(2022), stat_type= "shooting", team_or_player= "team") + expect_type(big5_team_shooting, "list") + expect_false(nrow(big5_team_shooting) == 0) + + big5_player_shooting <- load_fb_big5_advanced_season_stats(season_end_year= c(2022), stat_type= "shooting", team_or_player= "player") + expect_type(big5_player_shooting, "list") + expect_false(nrow(big5_player_shooting) == 0) + + bad_df <- load_fb_big5_advanced_season_stats(season_end_year= c(2022), stat_type= "foo", team_or_player= "player") + expect_true(nrow(bad_df) == 0) +}) diff --git a/tests/testthat/test-transfermarkt.R b/tests/testthat/test-transfermarkt.R index 25b7cbdd..13e7bf79 100644 --- a/tests/testthat/test-transfermarkt.R +++ b/tests/testthat/test-transfermarkt.R @@ -80,7 +80,7 @@ test_that("tm_player_bio() works", { # then pass all those URLs to the tm_player_bio burnley_bios <- tm_player_bio(player_urls = burnley_player_urls[1:3]) expect_type(burnley_bios, "list") - expect_equal(ncol(burnley_bios), 23) + expect_equal(ncol(burnley_bios), 21) }) diff --git a/vignettes/extract-fbref-data.Rmd b/vignettes/extract-fbref-data.Rmd index 84bd0dd2..20e9c421 100644 --- a/vignettes/extract-fbref-data.Rmd +++ b/vignettes/extract-fbref-data.Rmd @@ -59,6 +59,7 @@ Package vignettes have been built to help you get started with the package. * For functions to extract data from Understat, see [here](https://jaseziv.github.io/worldfootballR/articles/extract-understat-data.html) * For functions to extract data from fotmob, see [here](https://jaseziv.github.io/worldfootballR/articles/extract-fotmob-data.html) * For functions to extract data for international matches from FBref, see [here](https://jaseziv.github.io/worldfootballR/articles/fbref-data-internationals.html) +* For functions to load pre-scraped data, see [here](https://jaseziv.github.io/worldfootballR/articles/load-scraped-data.html) This vignette will cover the functions to extract data from FBref.com. diff --git a/vignettes/extract-fotmob-data.Rmd b/vignettes/extract-fotmob-data.Rmd index 92729127..fcc5201a 100644 --- a/vignettes/extract-fotmob-data.Rmd +++ b/vignettes/extract-fotmob-data.Rmd @@ -58,6 +58,7 @@ Package vignettes have been built to help you get started with the package. - For functions to extract data from Transfermarkt, see [here](https://jaseziv.github.io/worldfootballR/articles/extract-transfermarkt-data.html) - For functions to extract data from Understat, see [here](https://jaseziv.github.io/worldfootballR/articles/extract-understat-data.html) - For functions to extract data for international matches from FBref, see [here](https://jaseziv.github.io/worldfootballR/articles/fbref-data-internationals.html) +* For functions to load pre-scraped data, see [here](https://jaseziv.github.io/worldfootballR/articles/load-scraped-data.html) This vignette will cover the functions to extract data from fotmob.com diff --git a/vignettes/extract-transfermarkt-data.Rmd b/vignettes/extract-transfermarkt-data.Rmd index ab8a395e..e07c71bf 100644 --- a/vignettes/extract-transfermarkt-data.Rmd +++ b/vignettes/extract-transfermarkt-data.Rmd @@ -59,6 +59,7 @@ Package vignettes have been built to help you get started with the package. * For functions to extract data from Understat, see [here](https://jaseziv.github.io/worldfootballR/articles/extract-understat-data.html) * For functions to extract data from fotmob, see [here](https://jaseziv.github.io/worldfootballR/articles/extract-fotmob-data.html) * For functions to extract data for international matches from FBref, see [here](https://jaseziv.github.io/worldfootballR/articles/fbref-data-internationals.html) +* For functions to load pre-scraped data, see [here](https://jaseziv.github.io/worldfootballR/articles/load-scraped-data.html) This vignette will cover the functions to extract data from transfermarkt.com diff --git a/vignettes/extract-understat-data.Rmd b/vignettes/extract-understat-data.Rmd index 1cbfa60c..5d4bf3e2 100644 --- a/vignettes/extract-understat-data.Rmd +++ b/vignettes/extract-understat-data.Rmd @@ -59,6 +59,7 @@ Package vignettes have been built to help you get started with the package. * For functions to extract data from Transfermarkt, see [here](https://jaseziv.github.io/worldfootballR/articles/extract-transfermarkt-data.html) * For functions to extract data from fotmob, see [here](https://jaseziv.github.io/worldfootballR/articles/extract-fotmob-data.html) * For functions to extract data for international matches from FBref, see [here](https://jaseziv.github.io/worldfootballR/articles/fbref-data-internationals.html) +* For functions to load pre-scraped data, see [here](https://jaseziv.github.io/worldfootballR/articles/load-scraped-data.html) This vignette will cover the functions to extract data from understat.com diff --git a/vignettes/fbref-data-internationals.Rmd b/vignettes/fbref-data-internationals.Rmd index ee63ba5d..8a53fe57 100644 --- a/vignettes/fbref-data-internationals.Rmd +++ b/vignettes/fbref-data-internationals.Rmd @@ -59,6 +59,7 @@ Package vignettes have been built to help you get started with the package. * For functions to extract data from Transfermarkt, see [here](https://jaseziv.github.io/worldfootballR/articles/extract-transfermarkt-data.html) * For functions to extract data from Understat, see [here](https://jaseziv.github.io/worldfootballR/articles/extract-understat-data.html) * For functions to extract data from fotmob, see [here](https://jaseziv.github.io/worldfootballR/articles/extract-fotmob-data.html) +* For functions to load pre-scraped data, see [here](https://jaseziv.github.io/worldfootballR/articles/load-scraped-data.html) This vignette will cover the functions to extract data for international matches from FBref.com. diff --git a/vignettes/load-scraped-data.Rmd b/vignettes/load-scraped-data.Rmd new file mode 100644 index 00000000..563a2ea2 --- /dev/null +++ b/vignettes/load-scraped-data.Rmd @@ -0,0 +1,99 @@ +--- +title: "Load Scraped Data Functions" +author: "Jason Zivkovic" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Extracting data from FBref} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + message=FALSE, + warning=FALSE +) +``` + + +## Overview + +This package is designed to allow users to extract various world football results and player statistics from the following popular football (soccer) data sites: + +* [FBref](https://fbref.com/en/) +* [Transfermarkt](https://www.transfermarkt.com/) +* [Understat](https://understat.com/) +* [Fotmob](https://www.fotmob.com/) + + +## Installation + +You can install the CRAN version of [**```worldfootballR```** ](https://CRAN.R-project.org/package=worldfootballR) with: + +```{r cran-installation, eval=FALSE} +install.packages("worldfootballR") +``` + +You can install the released version of [**```worldfootballR```**](https://github.com/JaseZiv/worldfootballR/) from [GitHub](https://github.com/JaseZiv/worldfootballR) with: + +```{r gh-installation, eval=FALSE} +# install.packages("devtools") +devtools::install_github("JaseZiv/worldfootballR") +``` + + +```{r load_libs, warning=FALSE, message=FALSE} +library(worldfootballR) +``` + +*** + +## Usage + +Package vignettes have been built to help you get started with the package. + +* For functions to extract data from Transfermarkt, see [here](https://jaseziv.github.io/worldfootballR/articles/extract-transfermarkt-data.html) +* For functions to extract data from Understat, see [here](https://jaseziv.github.io/worldfootballR/articles/extract-understat-data.html) +* For functions to extract data from fotmob, see [here](https://jaseziv.github.io/worldfootballR/articles/extract-fotmob-data.html) +* For functions to extract data for international matches from FBref, see [here](https://jaseziv.github.io/worldfootballR/articles/fbref-data-internationals.html) +* For functions to load pre-scraped data, see [here](https://jaseziv.github.io/worldfootballR/articles/load-scraped-data.html) + +This vignette will cover the functions to load scraped data from the [`worldfootballR_data`](https://github.com/JaseZiv/worldfootballR_data) data repository. + +**NOTE:** + +As of version `0.5.2`, all FBref functions now come with a user-defined pause between page loads to address their new rate limiting. See [this](https://www.sports-reference.com/bot-traffic.html) document for more information. + + +*** + +## Load FBref match results + +To load pre-scraped match results for all years the data is available, the `load_match_results()` function can be used. This data is scheduled to be updated most days and a print statement will inform the user of when the data was last updated. All domestic leagues are included in the data repository. + +This is the load function equivalent of `get_match_results()`. + +```{r load_match_results, eval=FALSE} +eng_match_results <- load_match_results(country = "ENG", gender = c("M", "F"), season_end_year = c(2020:2022), tier = "1st") +dplyr::glimpse(eng_match_results) +``` + + +## Load FBref big 5 league advanced seasdon stats + +To load pre-scraped advanced stats for the big five European leagues for either teams or players, the `load_fb_big5_advanced_season_stats()` can be used. This data is scheduled to be updated most days and a print statement will inform the user of when the data was last updated. + +This is the load function equivalent of `get_match_results()`. + +```{r, load_adv_stats} +all_season_player <- load_fb_big5_advanced_season_stats(stat_type = "defense", team_or_player = "player") +current_season_player <- load_fb_big5_advanced_season_stats(season_end_year = 2022, stat_type = "defense", team_or_player = "player") + +all_season_team <- load_fb_big5_advanced_season_stats(stat_type = "defense", team_or_player = "team") +current_season_team <- load_fb_big5_advanced_season_stats(season_end_year = 2022, stat_type = "defense", team_or_player = "team") +``` + +