wiscostret / fplscrapR

This package enables those interested in Fantasy Premier League to perform detailed data analysis of the game, using the FPL's JSON API. The fplscrapR functions help R users collect and parse data from the Official Fantasy Premier League website.
Creative Commons Zero v1.0 Universal
76 stars 16 forks source link

Error message from "get_player_details() " #10

Closed ejlamarque closed 4 years ago

ejlamarque commented 4 years ago

Hi everybody. Just contacting you by the error from get_player_details() from gplscrapR

When I run it

library(fplscrapR)

df <- get_player_details()

give me the following error:

library(fplscrapR) df <- get_player_details() # this may take a while to load as it fetches ALL player details Error in data.frame(fplboot, playername = elements$playername[which(elements$id == : arguments imply differing number of rows: 0, 1

| >

Sometimes manage to pass this step clearly

df 589 obs. of 54 variables

and when I run the next step

df %>% filter(round %in% 1:20) %>% # filtering for the GWs we are interested in select(playername,goals_scored,assists) %>% # selecting the relevant columns group_by(playername) %>% # transformation to group and summarize the performance at the 'playername' variable level summarize_all(sum) %>% mutate("involvements"=goals_scored+assists) %>% # adding a new variable that sums the goals scored and assists arrange(-involvements) %>% # ordering (arranging) the table by top involvements slice(1:20) # showing the top20 only

give me the following error message

df %>%

  • filter(round %in% 1:20) %>% # filtering for the GWs we are interested in
  • select(playername,goals_scored,assists) %>% # selecting the relevant columns
  • group_by(playername) %>% # transformation to group and summarize the performance at the 'playername' variable level
  • summarize_all(sum) %>%
  • mutate("involvements"=goals_scored+assists) %>% # adding a new variable that sums the goals scored and assists
  • arrange(-involvements) %>% # ordering (arranging) the table by top involvements
  • slice(1:20) # showing the top20 only Error in match(x, table, nomatch = 0L) : 'match' requires vector arguments

And before didn't happen and run properly.

If you could take a look I appreciate it. For any further information or details don't hesitate to contact me.

Thank you. Enrique

wiscostret commented 4 years ago

Thanks for pointing this out!

The issue in get_player_details() is due to FPL having added a number of January signings (e.g. Takumi Minamino) to the game without detailed histories. This might be a new practice, or I just haven't noticed it before. This would only be a problem until the next gameweek starts (tonight), when the player histories would be automatically updated, and the function shouldn't produce an error after that.

In any case, I have pushed a fix to the package so the function will now work always. This produces a full list of players, including newly added ones, with 'NA' data points for their histories. You can update the package by re-installing using the 'install_github' function from the remotes or devtools libraries.

Once you have updated the package, the second issue - related to the vignette for identifying the top 20 players by FPL goal involvement - is fixed by adding a filter to remove the newly added players. You can, for instance, add "filter(!is.na(element))" to the pipe. Again, however, I note that this will only be a problem until the next gameweek starts.

Hope this helps.

ejlamarque commented 4 years ago

Amazing as usually!!!! Everything is working perfect again. Thank you so much for the quick answer. By the way, I will install the package and update the vignette just in case. Thank you again.