Suppose now we are interested in finding the names of the goalscorers in a given game? Here we take the example of the first fixture of the season.

First we fetch the game stats using get_game_stats:

library(fplscrapR)

df <- get_game_stats(gameid=1)

Next we identify the goalscorers’ playerids:

goalscorerids <- unlist(list(df$a[[1]]$element,df$h[[1]]$element))

Finally we fetch the playernames of goalscorers using get_player_name:

get_player_name(playerid=goalscorerids)
##           playername id
## 1 Christian Nørgaard 77
## 2        Sergi Canós 81