JaseZiv/worldfootballR

fb_advanced_match_stats not working for bundesliga

Closed this issue · 3 comments

Please include a minimal reproducible example (AKA a reprex). If you've never heard of a reprex before, start by reading https://www.tidyverse.org/help/#reprex.

If you don't already have the lastest version of the package, please try downloading it with remotes::install_github("JaseZiv/worldfootballR"), restarting your R session, and then trying your code againl.

When submitting your issue, feel free to delete everything above the line below, since this text is just intended to help you submit an informative issue.


{{Brief description of the problem}}

library(worldfootballR)
packageVersion("worldfootballR")

# insert code here
urls <- fb_match_urls(country = "GER", gender = "M", season_end_year = year, tier = "1st")
      df <- fb_advanced_match_stats(match_url = urls, stat_type = stat_type, team_or_player = "player")
sessionInfo()
With this code I could get everything except 'summary'. Same thing happened in France league. 
This is the message I got : 
%Error in map(.x, .f, ...) :In index: 307.
Caused by error in `data.frame()`:
! arguments imply differing number of rows: 1, 0

Are you still experiencing this issue? If so, can you please provide a full MRE - you have variables called year and stat_type in your example - I just need the actual values that are causing you issues.

Thanks

urls <- fb_match_urls(country = "GER", gender = "M", season_end_year = 2018, tier = "1st")
df <- fb_advanced_match_stats(match_url = urls, stat_type = "summary", team_or_player = "player")
Code worked perfectly for English, Spanish and Italian leagues but not working for French and German leagues. I've updated R and worldfootballR to the latest version and happened again. So I tried different years from 2018 to 2023 but still doesn't work for all of those years.

Ok so I think I know why this is. I haven't been able to recreate the errors you're getting in Ligue 1, but see below for Bundesliga.

The last two match URLs in Germany are for relegation/promotion matches, and these don't appear to have data on FBref:

image

I'll work on addressing this bug to handle errors gracefully and not fail all data returns.

In the meantime, a workaround for you for now is to exclude those URLs:

# first get the match URLs
urls <- worldfootballR::fb_match_urls(country = "GER", gender = "M", season_end_year = 2023, tier = "1st")

# then exclude the promotion/relegation matches missing data
urls_no_qual <- urls[-grep("Promotion", urls)]

# then use those in the function:
df <- worldfootballR::fb_advanced_match_stats(match_url = urls_no_qual, stat_type = "summary", team_or_player = "player")