The high-level team APIs intend to provide convenient functionality used by most users. Each function from the teams API returns a data frame with the requested data processed to serve common purposes.
Note that while some of the showcased examples use the
dplyr
package to manipulate the data, the
nhlapi
package itself does not import it and the user is
free to use whichever methods to manipulate the data.
There is a lot of information about games in the API, for instance, full details of the previous of the Devils:
# First get the API URL for the relevant game
game_url <- nhl_teams_shedule_previous(1) %>%
extract2("previousGameSchedule.dates") %>% first() %>%
extract2("games") %>% first() %>%
extract2("link")
# Now use `nhl_get_data()` to retrieve the data
game_data <- file.path("https://statsapi.web.nhl.com", game_url) %>%
nhl_get_data()
# This is a very complex nested endpoint, for instance,
# look at the recorded events in the game
game_plays <- game_data %>% first() %>%
extract2("liveData") %>%
extract2("plays") %>%
extract2("allPlays") %>%
as_tibble()
game_plays
# Get 2 seasons for the Devils:
devils_stats <- nhl_teams_stats(1, 2005:2006)
# Look at the teamStats object for the first of them
# Requires `dplyr` attached using library
devils_stats %>%
extract2("teamStats") %>% first() %>%
extract2("splits") %>% first() %>%
slice(1) %>%
select(stat.gamesPlayed, stat.wins, stat.losses)