JaseZiv / worldfootballR

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

fb_league_stats not returning anything other than "shooting" for players #395

Closed skbush22 closed 1 month ago

skbush22 commented 2 months ago

Earlier today I installed the package and went to run it for the first time, to get shooting data from FBref for MLS players. This worked fine. I then tried to retrieve passing data in the same way and ran into an issue. I received the following error: "Error: Request failed after 3 attempts." This occurred every time I tried to retrieve data other than "shooting". I set the country parameter to "ENG" and had the same issue. I'm sure I must be doing something wrong, just not sure what. I followed the instructions from the "Extracting data from FBref" docs and didn't make many changes other than to set it to MLS. Again, it worked for shooting but nothing else. This is the list of paramaters I tried: Standard, passing, passing_types, gca, defense, possession, playing_time, misc, keepers, keepers_adv. None worked. The code I used was the same for every single one expect for the stat_type parameter, obviously.

Also worth to note that while I was testing every stat_type, it essentially crashed my R and I had to restart multiple times. I had the same issue every time.

library(worldfootballR)
library(dplyr)

mls_2024_stats <- fb_league_stats(
  country = "USA",
  gender = "M",
  season_end_year = 2024,
  tier = "1st",
  non_dom_league_url = NA,
  stat_type = "passing",
  team_or_player = "player"
)
sessionInfo()

Here is what I got for session info:

Screenshot 2024-08-31 at 7 57 01 PM

Here is the error message:

Screenshot 2024-08-31 at 8 02 39 PM

Sorry in advance if I'm just doing something really dumb and not catching it! Thanks!

tonyelhabr commented 2 months ago

Thanks for filing this issue! If you look at the closed issues--like this one--you'll see that you're not the only one who has faced this issue. fb_league_stats is different than basically every other fb_ function in this package because it pulls data that is loaded "client-side", meaning we have to use a different kind of method to scrape the data. Our method relies on chromote and "promises", which can be unreliable--more detail here.

Our current implementation of fb_league_stats() uses old dev code written for read_html_live() before it was formally exposed in {rvest} (starting with version 1.0.4) in February. I think it's time that I try refactoring the code to fb_league_stats() to see if there's improvement with the reliability of this function. Stay tuned...

skbush22 commented 2 months ago

Ah, sorry I didn't see the old issue that had already been brought up, I looked through the Issues page but obviously missed that one. I see. If I had read the documentation a little more carefully, I would have seen there was a much easier way to achieve what I was trying to do anyways, but thank you for responding so quickly. I'm a noob with R but it's a great package regardless!