JaseZiv / worldfootballR

A wrapper for extracting world football (soccer) data from FBref, Transfermark, Understat
https://jaseziv.github.io/worldfootballR/
442 stars 60 forks source link

Extracting misc stat type #384

Closed James-O-Ball closed 1 week ago

James-O-Ball commented 3 weeks ago

{{I require some variables from the 'Misc' stat type, however they do not pull when manually extracting the data. I have also tried using the pre-scraped data and noticed this is still occurring. 'Misc' stats are pulling for some games within the English division, however no games at all in the Spanish league. The code below is what I have used to extract the pre-scraped data. }}

library(worldfootballR)
packageVersion("worldfootballR")

# Define the parameters
countries <- 'ESP'
gender <- 'M'
tier <- '1st'
season_end_years <- c (2023, 2024)
stat_types <- c('summary', 'passing', 'passing_types', 'defense', 'possession' 'misc')

# Loop through each combination of season_end_year and stat_type
for (season in season_end_years) {
  for (stat in stat_types) {
    # Load the data
    data <- load_fb_advanced_match_stats(
      country = countries,
      gender = gender,
      tier = tier,
      season_end_year = season,
      stat_type = stat,
      team_or_player = 'player'
    )

    # Create a variable name based on the parameters
    var_name <- paste0('ESP_', season, '_', stat)

    # Assign the data to the variable
    assign(var_name, data)
  }
}

sessionInfo()
tonyelhabr commented 3 weeks ago

You are correct that misc + player data is not available right now for load_fb_advanced_match_stats(). This is because this combination of parameters is the last that we attempt to scrape (after many other parameter combinations) and is therefore the most unlikely to be reached before the job randomly fails or times out. I'll work on adding it.

In the meantime, you could use fb_advanced_match_stats after pulling a vector of match urls for the season. Oh, and make sure that there is a comma between 'possession' and 'misc' in your stat_types vector :smile:.

tonyelhabr commented 2 weeks ago

@James-O-Ball If you try again (and add the comma before misc in your stat_types vector), it should work now. I've finished backfilling this stat for ESP. I'm still backfilling for other leagues.

tonyelhabr commented 1 week ago

closing since i got a thumbs-up