StatsBombR icon indicating copy to clipboard operation
StatsBombR copied to clipboard

getallinfo() fails in some cases due to first element of myList being NULL

Open JoGall opened this issue 7 years ago • 0 comments

I'd make this a pull request but I'm running a much different fork of the package for use with R <v5.0.

getallinfo() is failing currently for the latest FA WSL fixtures due to some weirdness in match_id == 19790:

Reprex:

library(dplyr)
library(StatsBombR)

# get all available fixtures from StatsBomb
fixture <- FreeMatches(37) %>% 
  filter(match_id == 19790)

getallinfo(fixture)

# Error in matrix(ncol = ncol(myList[[1]]), nrow = 1) : non-numeric matrix extent

Going through step-by-step, it's functions goalkeeperinfo() and freezeframeinfo() that fail; in both cases seems to be due to the first entry of Shots.FF being NULL, causing the fixnull function to fail.

A simple fix is to use the first non-null of myList in fixnull, changing line 13 of goalkeeperinfo.R and line 23 of freezeframeinfo from:

return(setNames(data.frame(matrix(ncol = ncol(myList[[1]]), nrow = 1)), names(myList[[1]])))

to:

return(setNames(data.frame(matrix(ncol = ncol(myList[lengths(myList) != 0][[1]]), nrow = 1)), names(myList[lengths(myList) != 0][[1]])))

JoGall avatar Feb 02 '19 17:02 JoGall