Title: | A Minimum-Dependency 'R' Interface to the 'NHL' API |
---|---|
Description: | Retrieves and processes the data exposed by the open 'NHL' API. This includes information on players, teams, games, tournaments, drafts, standings, schedules and other endpoints. A lower-level interface to access the data via URLs directly is also provided. |
Authors: | Jozef Hajnala [aut, cre] |
Maintainer: | Jozef Hajnala <[email protected]> |
License: | AGPL-3 |
Version: | 0.1.4.900 |
Built: | 2024-11-05 05:28:36 UTC |
Source: | https://github.com/jozefhajnala/nhlapi |
Create a log message
make_log( msg, ..., type = "I", dtFormat = getOption("nhlapi_log_datetime"), newLine = FALSE, sep = " | ", collapse = " ", lineBreak = "$", endNewLine = FALSE )
make_log( msg, ..., type = "I", dtFormat = getOption("nhlapi_log_datetime"), newLine = FALSE, sep = " | ", collapse = " ", lineBreak = "$", endNewLine = FALSE )
msg |
|
... |
additional |
type |
|
dtFormat |
|
newLine |
|
sep |
|
collapse |
|
lineBreak |
|
endNewLine |
|
character(1)
, constructed log message.
nhlapi:::make_log("Dummy warning", type = "W")
nhlapi:::make_log("Dummy warning", type = "W")
Retrieve metadata on NHL awards from the API
nhl_awards(awardIds = NULL)
nhl_awards(awardIds = NULL)
awardIds |
|
data.frame
, with information on awards, one row per award.
## Not run: # Get information on all awards nhl_awards() # Get information on 3 historical awards nhl_awards(1:3) ## End(Not run)
## Not run: # Get information on all awards nhl_awards() # Get information on 3 historical awards nhl_awards(1:3) ## End(Not run)
Retrieve metadata on NHL conferences from the API
nhl_conferences(conferenceIds = NULL)
nhl_conferences(conferenceIds = NULL)
conferenceIds |
|
data.frame
, with information on conferences, one row
per conference.
## Not run: # Get information on all conferences nhl_conferences() # Get information on 2 selected conferences nhl_conferences(5:6) ## End(Not run)
## Not run: # Get information on all conferences nhl_conferences() # Get information on 2 selected conferences nhl_conferences(5:6) ## End(Not run)
Retrieve metadata on NHL divisions from the API
nhl_divisions(divisionIds = NULL)
nhl_divisions(divisionIds = NULL)
divisionIds |
|
data.frame
, with information on divisions, one row
per division.
## Not run: # Get information on all divisions nhl_divisions() # Get information on 2 selected divisions nhl_divisions(15:16) ## End(Not run)
## Not run: # Get information on all divisions nhl_divisions() # Get information on 2 selected divisions nhl_divisions(15:16) ## End(Not run)
Retrieve metadata on NHL draft prospects from the API
nhl_draft_prospects(prospectIds = NULL)
nhl_draft_prospects(prospectIds = NULL)
prospectIds |
|
data.frame
, with information on draft prospects, one row
per draft prospect.
## Not run: # Get information on current draft prospects nhl_draft_prospects() ## End(Not run)
## Not run: # Get information on current draft prospects nhl_draft_prospects() ## End(Not run)
Retrieve metadata on NHL drafts from the API
nhl_drafts(draftYears = NULL)
nhl_drafts(draftYears = NULL)
draftYears |
|
data.frame
, with information on drafts, one row
per draft year.
## Not run: # Get information on current draft nhl_drafts() # Get information on 3 historical drafts nhl_drafts(2015:2017) ## End(Not run)
## Not run: # Get information on current draft nhl_drafts() # Get information on 3 historical drafts nhl_drafts(2015:2017) ## End(Not run)
fromJSON
Get URL using fromJSON
nhl_from_json( url, flatten = getOption("nhlapi_flatten"), silent = getOption("nhlapi_try_silent"), retries = getOption("nhlapi_get_retries"), retrySleep = getOption("nhlapi_get_retry_sleep"), noRetryPatt = getOption("nhlapi_get_noretry") )
nhl_from_json( url, flatten = getOption("nhlapi_flatten"), silent = getOption("nhlapi_try_silent"), retries = getOption("nhlapi_get_retries"), retrySleep = getOption("nhlapi_get_retry_sleep"), noRetryPatt = getOption("nhlapi_get_noretry") )
url |
|
flatten |
|
silent |
|
retries |
|
retrySleep |
|
noRetryPatt |
|
list
, retrieved data if succeeded, a try-error
class
object otherwise.
Retrieve metadata on NHL games from the API
nhl_games(gameIds, element) nhl_games_content(gameIds) nhl_games_feed(gameIds) nhl_games_boxscore(gameIds) nhl_games_linescore(gameIds)
nhl_games(gameIds, element) nhl_games_content(gameIds) nhl_games_feed(gameIds) nhl_games_boxscore(gameIds) nhl_games_linescore(gameIds)
gameIds |
|
element |
|
list
, with information on games, one element per game
and element combination.
nhl_games_content
: Complex endpoint returning multiple types
of media relating to the game including videos of shots,
goals and saves.
nhl_games_feed
: returns all data about a specified game id
including play data with on-ice coordinates and post-game
details like first, second and third stars and details about
shootouts. Note that the data returned is sizable, often over
30 000 lines.
nhl_games_boxscore
: Returns far less detail than nhl_games_feed()
and may be more suitable for analyzing post-game statistics
including goals, shots, penalty minutes, blocked, takeaways, etc.
nhl_games_linescore
: Returns even fewer details than
nhl_games_boxscore()
. Has goals, shots on goal, power-play
and goalie pulled status, number of skaters and shootout
information if applicable.
## Not run: # Get content for one game nhl_games(2017010001, "content") # Get both box score and content for 2 games nhl_games(c(2017010001, 2017010002), c("content", "boxscore")) # Get content for a game nhl_games_content(2017010001) # Get the game feed for a game nhl_games_feed(2017010001) # Get the box score for a game nhl_games_boxscore(2017010001) # Get the line score for a game nhl_games_linescore(2017010001) ## End(Not run)
## Not run: # Get content for one game nhl_games(2017010001, "content") # Get both box score and content for 2 games nhl_games(c(2017010001, 2017010002), c("content", "boxscore")) # Get content for a game nhl_games_content(2017010001) # Get the game feed for a game nhl_games_feed(2017010001) # Get the box score for a game nhl_games_boxscore(2017010001) # Get the line score for a game nhl_games_linescore(2017010001) ## End(Not run)
Get data from the API for one or more URLs
nhl_get_data(urls, flatten = getOption("nhlapi_flatten"))
nhl_get_data(urls, flatten = getOption("nhlapi_flatten"))
urls |
|
flatten |
|
list
, results retrieved using nhl_get_data_worker()
.
One element per url. The elements contain the retrieved data
if retrieval succeeded, otherwise an nhl_get_data_error
class
object.
## Not run: nhl_get_data(c( "https://statsapi.web.nhl.com/api/v1/teams/1", "https://statsapi.web.nhl.com/api/v1/people/8477474" )) nhl_get_data( "https://statsapi.web.nhl.com/api/v1/teams/1", flatten = FALSE ) ## End(Not run)
## Not run: nhl_get_data(c( "https://statsapi.web.nhl.com/api/v1/teams/1", "https://statsapi.web.nhl.com/api/v1/people/8477474" )) nhl_get_data( "https://statsapi.web.nhl.com/api/v1/teams/1", flatten = FALSE ) ## End(Not run)
Gets data from the NHL API using nhl_from_json()
.
nhl_get_data_worker( url, flatten = getOption("nhlapi_flatten"), silent = getOption("nhlapi_try_silent"), retries = getOption("nhlapi_get_retries"), retrySleep = getOption("nhlapi_get_retry_sleep") )
nhl_get_data_worker( url, flatten = getOption("nhlapi_flatten"), silent = getOption("nhlapi_try_silent"), retries = getOption("nhlapi_get_retries"), retrySleep = getOption("nhlapi_get_retry_sleep") )
url |
|
flatten |
|
silent |
|
retries |
|
retrySleep |
|
list
, with the retrieved data or class nhl_get_data_error
.
The NHL API wants seasons defined in format
"YYYYZZZZ"
where ZZZZ = YYYY + 1
. This is a helper to take
a vector of years in "YYYY"
format and create a vector of
such seasons to be used with the API.
nhl_make_seasons(seasons = 1950:2019)
nhl_make_seasons(seasons = 1950:2019)
seasons |
Alternatively, also accepts Some API endpoints, notably |
character()
, vector of seasons suited for the NHL API.
nhlapi:::nhl_make_seasons() nhlapi:::nhl_make_seasons(1995:2000) nhlapi:::nhl_make_seasons(c(1995, 2015)) nhlapi:::nhl_make_seasons(c("1995", "2015"))
nhlapi:::nhl_make_seasons() nhlapi:::nhl_make_seasons(1995:2000) nhlapi:::nhl_make_seasons(c(1995, 2015)) nhlapi:::nhl_make_seasons(c("1995", "2015"))
Get event types metadata
nhl_md_event_types()
nhl_md_event_types()
list
, with metadata on event types.
Get game status metadata
nhl_md_game_statuses()
nhl_md_game_statuses()
list
, with metadata on game statuses.
Get game type metadata
nhl_md_game_types()
nhl_md_game_types()
list
, with metadata on game types.
Get play types metadata
nhl_md_play_types()
nhl_md_play_types()
list
, with metadata on play types.
Get standings types metadata
nhl_md_standings_types()
nhl_md_standings_types()
list
, with metadata on standings types.
Get stat types metadata
nhl_md_stat_types()
nhl_md_stat_types()
list
, with metadata on stat types.
Get tournament types metadata
nhl_md_tournament_types()
nhl_md_tournament_types()
list
, with metadata on tournament types.
Retrieves information on players from the NHL API based on
playerNames
or playerIds
. If playerNames
are provided,
they take precedence over playerIds
.
nhl_players(playerNames, playerIds = NULL)
nhl_players(playerNames, playerIds = NULL)
playerNames |
|
playerIds |
|
data.frame
, with information on selected players.
## Not run: # With player names nhl_players(c("joe SAKIC", "patrick roy")) # With playerIds nhl_players(playerIds = c(8451101, 8458554)) ## End(Not run)
## Not run: # With player names nhl_players(c("joe SAKIC", "patrick roy")) # With playerIds nhl_players(playerIds = c(8451101, 8458554)) ## End(Not run)
Retrieve all seasons statistics for players
nhl_players_allseasons(playerNames, playerIds = NULL)
nhl_players_allseasons(playerNames, playerIds = NULL)
playerNames |
|
playerIds |
|
data.frame
, with all season statistics for
selected players.
## Not run: # With player names nhl_players_allseasons(c("joe sakic", "Peter Forsberg")) # With player ids nhl_players_allseasons(c(8451101, 8458554)) ## End(Not run)
## Not run: # With player names nhl_players_allseasons(c("joe sakic", "Peter Forsberg")) # With player ids nhl_players_allseasons(c(8451101, 8458554)) ## End(Not run)
Retrieve selected seasons statistics for players
nhl_players_seasons(playerNames, seasons, playerIds = NULL, playoffs = FALSE)
nhl_players_seasons(playerNames, seasons, playerIds = NULL, playoffs = FALSE)
playerNames |
|
seasons |
Alternatively, also accepts Some API endpoints, notably |
playerIds |
|
playoffs |
|
data.frame
, with selected season statistics
for selected players.
## Not run: nhl_players_seasons( playerIds = c(8451101, 8458554), seasons = "19951996", playoffs = TRUE ) ## End(Not run)
## Not run: nhl_players_seasons( playerIds = c(8451101, 8458554), seasons = "19951996", playoffs = TRUE ) ## End(Not run)
Initialize a plot in base graphics with a to-scale NHL rink as the background
nhl_plot_rink()
nhl_plot_rink()
The placement of rink features & their sizes are exact according to the NHL rule book; see citation.
## Not run: # Retrieve some game feed data gameFeeds <- lapply( 2019010001:2019010010, nhlapi::nhl_games_feed ) # Create a data.frame with plays getPlaysDf <- function(gm) { playsRes <- try(gm[[1L]][["liveData"]][["plays"]][["allPlays"]]) if (inherits(playsRes, "try-error")) data.frame() else playsRes } plays <- lapply(gameFeeds, getPlaysDf) plays <- nhlapi:::util_rbindlist(plays) plays <- plays[!is.na(plays$coordinates.x), ] # Move the coordinates to non-negative values before plotting plays$coordx <- plays$coordinates.x + abs(min(plays$coordinates.x)) plays$coordy <- plays$coordinates.y + abs(min(plays$coordinates.y)) # Select goals only goals <- plays[plays$result.event == "Goal", ] # Create the plot and add goals nhlapi::plot_rink() points(goals$coordinates.x, goals$coordinates.y) ## End(Not run)
## Not run: # Retrieve some game feed data gameFeeds <- lapply( 2019010001:2019010010, nhlapi::nhl_games_feed ) # Create a data.frame with plays getPlaysDf <- function(gm) { playsRes <- try(gm[[1L]][["liveData"]][["plays"]][["allPlays"]]) if (inherits(playsRes, "try-error")) data.frame() else playsRes } plays <- lapply(gameFeeds, getPlaysDf) plays <- nhlapi:::util_rbindlist(plays) plays <- plays[!is.na(plays$coordinates.x), ] # Move the coordinates to non-negative values before plotting plays$coordx <- plays$coordinates.x + abs(min(plays$coordinates.x)) plays$coordy <- plays$coordinates.y + abs(min(plays$coordinates.y)) # Select goals only goals <- plays[plays$result.event == "Goal", ] # Create the plot and add goals nhlapi::plot_rink() points(goals$coordinates.x, goals$coordinates.y) ## End(Not run)
The general-purpose nhl_schedule()
exposes many parameters,
some useful helpers are exposed as separate functions to
reflect common use cases. Arguments can be passed to these
named via ...
.
nhl_schedule( seasons = NULL, teamIds = NULL, startDate = NULL, endDate = NULL, gameTypes = NULL, expand = NULL ) nhl_schedule_today(...) nhl_schedule_seasons(seasons, ...) nhl_schedule_date_range(startDate, endDate, ...)
nhl_schedule( seasons = NULL, teamIds = NULL, startDate = NULL, endDate = NULL, gameTypes = NULL, expand = NULL ) nhl_schedule_today(...) nhl_schedule_seasons(seasons, ...) nhl_schedule_date_range(startDate, endDate, ...)
seasons |
Alternatively, also accepts Some API endpoints, notably |
teamIds |
|
startDate |
|
endDate |
|
gameTypes |
|
expand |
|
... |
other named parameters passed to |
list
, with information on schedule, depending on
provided arguments.
nhl_schedule_today
: Shortcut to get information on
today's schedule.
nhl_schedule_seasons
: Shortcut to get information on schedule for
one or more seasons.
nhl_schedule_date_range
: Shortcut to get information on
schedule for a range of dates in "YYYY-MM-DD"
format.
## Not run: # Get current schedule nhl_schedule() # Get schedule for historical seasons nhl_schedule(seasons = 2015:2016) # Get schedule for a date range nhl_schedule(startDate = "2018-01-02", endDate = "2018-01-02") # Get schedule for a date range, specific teams # and expand on line scores nhl_schedule( startDate = "2018-01-02", endDate = "2018-01-02", teamIds = c(29, 30), expand = "schedule.linescore" ) ## End(Not run) ## Not run: nhl_schedule_today() ## End(Not run) ## Not run: # Schedule for seasons starting in 2015 and 2016 nhl_schedule_seasons(2015:2016) # Schedule for seasons starting in 2015 and 2016 # Only 1 team and expand line scores nhl_schedule_seasons( 2015:2016, teamIds = 1, expand = "schedule.linescore" ) ## End(Not run) ## Not run: # Schedule for October and November 2015 nhl_schedule_date_range( startDate = "2015-10-01", endDate = "2015-11-30" ) # Schedule for October and November 2015 # Regular seasons only, specific team and expand line scores nhl_schedule_date_range( startDate = "2015-10-01", endDate = "2015-11-30", gameTypes = "R", teamIds = 2, expand = "schedule.linescore" ) ## End(Not run)
## Not run: # Get current schedule nhl_schedule() # Get schedule for historical seasons nhl_schedule(seasons = 2015:2016) # Get schedule for a date range nhl_schedule(startDate = "2018-01-02", endDate = "2018-01-02") # Get schedule for a date range, specific teams # and expand on line scores nhl_schedule( startDate = "2018-01-02", endDate = "2018-01-02", teamIds = c(29, 30), expand = "schedule.linescore" ) ## End(Not run) ## Not run: nhl_schedule_today() ## End(Not run) ## Not run: # Schedule for seasons starting in 2015 and 2016 nhl_schedule_seasons(2015:2016) # Schedule for seasons starting in 2015 and 2016 # Only 1 team and expand line scores nhl_schedule_seasons( 2015:2016, teamIds = 1, expand = "schedule.linescore" ) ## End(Not run) ## Not run: # Schedule for October and November 2015 nhl_schedule_date_range( startDate = "2015-10-01", endDate = "2015-11-30" ) # Schedule for October and November 2015 # Regular seasons only, specific team and expand line scores nhl_schedule_date_range( startDate = "2015-10-01", endDate = "2015-11-30", gameTypes = "R", teamIds = 2, expand = "schedule.linescore" ) ## End(Not run)
Retrieve metadata on NHL seasons from the API
nhl_seasons(seasons = NULL)
nhl_seasons(seasons = NULL)
seasons |
Alternatively, also accepts Some API endpoints, notably |
data.frame
, with information on seasons, one row
per year.
## Not run: # Get information on all seasons nhl_seasons() # Get information on 3 historical seasons nhl_seasons(2015:2017) ## End(Not run)
## Not run: # Get information on all seasons nhl_seasons() # Get information on 3 historical seasons nhl_seasons(2015:2017) ## End(Not run)
Retrieve metadata on NHL standings from the API
nhl_standings(seasons = NULL, standingsTypes = NULL, expand = NULL)
nhl_standings(seasons = NULL, standingsTypes = NULL, expand = NULL)
seasons |
Alternatively, also accepts Some API endpoints, notably |
standingsTypes |
|
expand |
|
list
, with information on standings
depending on provided arguments.
## Not run: # Get current standings nhl_standings() # Get standings for historical seasons nhl_standings(seasons = 2015:2016) # Get standings for historical seasons nhl_standings( seasons = 2015:2016, standingsType = "byDivision", expand = "standings.record" ) ## End(Not run)
## Not run: # Get current standings nhl_standings() # Get standings for historical seasons nhl_standings(seasons = 2015:2016) # Get standings for historical seasons nhl_standings( seasons = 2015:2016, standingsType = "byDivision", expand = "standings.record" ) ## End(Not run)
Retrieves team metadata such as the teams names, abbreviations, locations, conferences, venues, etc.
nhl_teams(teamIds = NULL, params = NULL)
nhl_teams(teamIds = NULL, params = NULL)
teamIds |
|
params |
|
The API allows to retrieve data on all teams at once,
which is achieved by the default NULL
value for the team id.
data.frame
, with data on teams, one row per team.
## Not run: nhl_teams() nhl_teams(1:3) ## End(Not run)
## Not run: nhl_teams() nhl_teams(1:3) ## End(Not run)
Get rosters for teams
nhl_teams_rosters(teamIds = NULL, seasons = NULL)
nhl_teams_rosters(teamIds = NULL, seasons = NULL)
teamIds |
|
seasons |
Alternatively, also accepts Some API endpoints, notably |
data.frame
, with an element called roster.roster
that in itself is a data.frame
with the roster data.
## Not run: # Current rosters for all teams nhl_teams_rosters() # Rosters for all teams for past seasons nhl_teams_rosters(seasons = c("19931994", "19931994")) # Roster for Devils and Islanders nhl_teams_rosters( teamIds = 1:2, seasons = c("19931994", "19931994") ) ## End(Not run)
## Not run: # Current rosters for all teams nhl_teams_rosters() # Rosters for all teams for past seasons nhl_teams_rosters(seasons = c("19931994", "19931994")) # Roster for Devils and Islanders nhl_teams_rosters( teamIds = 1:2, seasons = c("19931994", "19931994") ) ## End(Not run)
Get details for the teams' upcoming game
nhl_teams_shedule_next(teamIds = NULL)
nhl_teams_shedule_next(teamIds = NULL)
teamIds |
|
data.frame
, with elements with names starting with
nextGameSchedule
that contain data on the teams' upcoming
game. One row per team.
## Not run: # Next game for all teams nhl_teams_shedule_next() # Next game for selected teams nhl_teams_shedule_next(c(1,3,5)) ## End(Not run)
## Not run: # Next game for all teams nhl_teams_shedule_next() # Next game for selected teams nhl_teams_shedule_next(c(1,3,5)) ## End(Not run)
Get details for the teams' previous game
nhl_teams_shedule_previous(teamIds = NULL)
nhl_teams_shedule_previous(teamIds = NULL)
teamIds |
|
data.frame
, with elements with names starting with
previousGameSchedule
that contain data on the teams'
previous game. One row per team.
## Not run: # Next game for all teams nhl_teams_shedule_previous() # Next game for selected teams nhl_teams_shedule_previous(c(1,3,5)) ## End(Not run)
## Not run: # Next game for all teams nhl_teams_shedule_previous() # Next game for selected teams nhl_teams_shedule_previous(c(1,3,5)) ## End(Not run)
Get team statistics per seasons
nhl_teams_stats(teamIds = NULL, seasons = NULL)
nhl_teams_stats(teamIds = NULL, seasons = NULL)
teamIds |
|
seasons |
Alternatively, also accepts Some API endpoints, notably |
data.frame
, with seasons statistics for the selected
team(s), one row per each team and season combination.
## Not run: # All teams, current seasons nhl_teams_stats() # 2 teams, 3 seasons nhl_teams_stats(1:2, c("20052006", "20062007", "20072008")) ## End(Not run)
## Not run: # All teams, current seasons nhl_teams_stats() # 2 teams, 3 seasons nhl_teams_stats(1:2, c("20052006", "20062007", "20072008")) ## End(Not run)
Retrieve data on tournaments from the API
nhl_tournaments(tournamentTypes, seasons = NULL, expand = NULL) nhl_tournaments_playoffs(seasons = NULL, expand = NULL) nhl_tournaments_olympics(seasons = NULL, expand = NULL) nhl_tournaments_worldcups(seasons = NULL, expand = NULL)
nhl_tournaments(tournamentTypes, seasons = NULL, expand = NULL) nhl_tournaments_playoffs(seasons = NULL, expand = NULL) nhl_tournaments_olympics(seasons = NULL, expand = NULL) nhl_tournaments_worldcups(seasons = NULL, expand = NULL)
tournamentTypes |
Those are exposed via shorthand functions |
seasons |
Alternatively, also accepts Some API endpoints, notably |
expand |
|
list
, with information on tournaments, one element per
tournamentTypes
and parameters (seasons
and expand
)
combinations.
nhl_tournaments_playoffs
: Shortcut to get information on playoffs.
nhl_tournaments_olympics
: Shortcut to get information on Olympics.
nhl_tournaments_worldcups
: Shortcut to get information on world cups.
## Not run: # Get info on playoffs in one season nhl_tournaments("playoffs", 2015) # Get info on playoffs in 2 seasons, expand rounds nhl_tournaments("playoffs", 2015:2016, "round.series") ## End(Not run) ## Not run: nhl_tournaments_playoffs(2015:2016, "round.series") ## End(Not run) ## Not run: nhl_tournaments_olympics(2009, "round.series") ## End(Not run) ## Not run: nhl_tournaments_worldcups(2003) ## End(Not run)
## Not run: # Get info on playoffs in one season nhl_tournaments("playoffs", 2015) # Get info on playoffs in 2 seasons, expand rounds nhl_tournaments("playoffs", 2015:2016, "round.series") ## End(Not run) ## Not run: nhl_tournaments_playoffs(2015:2016, "round.series") ## End(Not run) ## Not run: nhl_tournaments_olympics(2009, "round.series") ## End(Not run) ## Not run: nhl_tournaments_worldcups(2003) ## End(Not run)
Create an NHL API URL
nhl_url( endPoint = NULL, suffixes = NULL, params = NULL, baseUrl = getOption("nhlapi_baseurl") )
nhl_url( endPoint = NULL, suffixes = NULL, params = NULL, baseUrl = getOption("nhlapi_baseurl") )
endPoint |
|
suffixes |
|
params |
|
baseUrl |
|
character()
, the created URLs.
nhlapi:::nhl_url("people", "8477474")
nhlapi:::nhl_url("people", "8477474")
Add parameters to URLs
nhl_url_add_params(url, params = NULL)
nhl_url_add_params(url, params = NULL)
url |
|
params |
|
character()
, URLs with parameters added. Same
length as all the combinations of url
and params
.
Add suffixes to URLs
nhl_url_add_suffixes(url, suffixes)
nhl_url_add_suffixes(url, suffixes)
url |
|
suffixes |
|
character()
, URLs with suffixes added. Same
length as all the combinations of url
and suffixes
.
Create an NHL API URL for awards
nhl_url_awards(awardIds = NULL)
nhl_url_awards(awardIds = NULL)
awardIds |
|
character()
, API URLs, same length as awardIds
or
length 1
if awardIds
is NULL
.
nhlapi:::nhl_url_awards() nhlapi:::nhl_url_awards(1:3)
nhlapi:::nhl_url_awards() nhlapi:::nhl_url_awards(1:3)
Create an NHL API URL for conferences
nhl_url_conferences(conferenceIds = NULL)
nhl_url_conferences(conferenceIds = NULL)
conferenceIds |
|
character()
, API URLs, same length as teamIds
or
length 1
if teamIds
is NULL
.
nhlapi:::nhl_url_conferences() nhlapi:::nhl_url_conferences(1:3)
nhlapi:::nhl_url_conferences() nhlapi:::nhl_url_conferences(1:3)
Create an NHL API URL for divisions
nhl_url_divisions(divisionIds = NULL)
nhl_url_divisions(divisionIds = NULL)
divisionIds |
|
character()
, of same length as teamIds
or length
1
if teamIds
is NULL
.
nhlapi:::nhl_url_divisions() nhlapi:::nhl_url_divisions(1:3)
nhlapi:::nhl_url_divisions() nhlapi:::nhl_url_divisions(1:3)
Create an NHL API URL for draft prospects
nhl_url_draft_prospects(prospectIds = NULL)
nhl_url_draft_prospects(prospectIds = NULL)
prospectIds |
|
character()
, API URLs, same length as prospectIds
or
length 1
if prospectIds
is NULL
.
nhlapi:::nhl_url_draft_prospects()
nhlapi:::nhl_url_draft_prospects()
Create an NHL API URL for drafts
nhl_url_drafts(draftYears = NULL)
nhl_url_drafts(draftYears = NULL)
draftYears |
|
character()
, API URLs, same length as draftYears
or
length 1
if draftYears
is NULL
.
nhlapi:::nhl_url_drafts() nhlapi:::nhl_url_drafts(2015:2017)
nhlapi:::nhl_url_drafts() nhlapi:::nhl_url_drafts(2015:2017)
Create an NHL API URL for games
nhl_url_games(gameIds, element)
nhl_url_games(gameIds, element)
gameIds |
|
element |
|
character()
, of same length as gameIds
.
nhlapi:::nhl_url_games(2017010001, "content") nhlapi:::nhl_url_games( c(2017010001, 2017010002), c("content", "boxscore") )
nhlapi:::nhl_url_games(2017010001, "content") nhlapi:::nhl_url_games( c(2017010001, 2017010002), c("content", "boxscore") )
Create an NHL API URL for players
nhl_url_players(playerIds)
nhl_url_players(playerIds)
playerIds |
|
character()
, API URLs, same length as playerIds
.
nhlapi:::nhl_url_players(playerIds = c(8477474, 8477475))
nhlapi:::nhl_url_players(playerIds = c(8477474, 8477475))
Create an NHL API URL for all players' seasons statistics
nhl_url_players_allseasons(playerIds)
nhl_url_players_allseasons(playerIds)
playerIds |
|
# Joe Sakic, all seasons nhlapi:::nhl_url_players_allseasons(8451101L)
# Joe Sakic, all seasons nhlapi:::nhl_url_players_allseasons(8451101L)
Create an NHL API URL for players' seasons statistics
nhl_url_players_seasons(playerIds, seasons, playoffs = FALSE)
nhl_url_players_seasons(playerIds, seasons, playoffs = FALSE)
playerIds |
|
seasons |
Alternatively, also accepts Some API endpoints, notably |
playoffs |
|
If multiple players and seasons are provided, URLs will be created for all combinations of players and seasons.
# Joe Sakic, regular season 1995/1996 nhlapi:::nhl_url_players_seasons(8451101L, 1995) # Joe Sakic, playoffs 1995/1996, 1996/1997 and 1997/1998 nhlapi:::nhl_url_players_seasons( 8451101L, 1995:1997, playoffs = TRUE )
# Joe Sakic, regular season 1995/1996 nhlapi:::nhl_url_players_seasons(8451101L, 1995) # Joe Sakic, playoffs 1995/1996, 1996/1997 and 1997/1998 nhlapi:::nhl_url_players_seasons( 8451101L, 1995:1997, playoffs = TRUE )
Create an NHL API stats URL for players
nhl_url_players_stats(playerIds, params = NULL)
nhl_url_players_stats(playerIds, params = NULL)
playerIds |
|
params |
|
character()
, of API URLs, same length as playerIds
.
nhlapi:::nhl_url_players_stats(8477474)
nhlapi:::nhl_url_players_stats(8477474)
Create an NHL API URL for schedules
nhl_url_schedule( seasons = NULL, teamIds = NULL, startDate = NULL, endDate = NULL, gameTypes = NULL, expand = NULL )
nhl_url_schedule( seasons = NULL, teamIds = NULL, startDate = NULL, endDate = NULL, gameTypes = NULL, expand = NULL )
seasons |
Alternatively, also accepts Some API endpoints, notably |
teamIds |
|
startDate |
|
endDate |
|
gameTypes |
|
expand |
|
character()
, vector of URLs.
nhlapi:::nhl_url_schedule(seasons = 2015:2016) nhlapi:::nhl_url_schedule( startDate = "2018-01-02", endDate = "2018-01-02" ) nhlapi:::nhl_url_schedule( startDate = "2018-01-02", endDate = "2018-01-02", teamIds = c(29, 30), expand = "schedule.linescore" )
nhlapi:::nhl_url_schedule(seasons = 2015:2016) nhlapi:::nhl_url_schedule( startDate = "2018-01-02", endDate = "2018-01-02" ) nhlapi:::nhl_url_schedule( startDate = "2018-01-02", endDate = "2018-01-02", teamIds = c(29, 30), expand = "schedule.linescore" )
Create an NHL API URL for seasons
nhl_url_seasons(seasons = NULL)
nhl_url_seasons(seasons = NULL)
seasons |
Alternatively, also accepts Some API endpoints, notably |
character()
, of API URLs, same length as seasons
or length 1
if seasons
is NULL
.
nhlapi:::nhl_url_seasons() nhlapi:::nhl_url_seasons(2015:2017) nhlapi:::nhl_url_seasons("20152016")
nhlapi:::nhl_url_seasons() nhlapi:::nhl_url_seasons(2015:2017) nhlapi:::nhl_url_seasons("20152016")
Create an NHL API URL for standings
nhl_url_standings(seasons = NULL, standingsTypes = NULL, expand = NULL)
nhl_url_standings(seasons = NULL, standingsTypes = NULL, expand = NULL)
seasons |
Alternatively, also accepts Some API endpoints, notably |
standingsTypes |
|
expand |
|
character()
, vector of URLs.
nhlapi:::nhl_url_standings(seasons = 2015:2016) nhlapi:::nhl_url_standings( standingsType = "byDivision", expand = "standings.record" )
nhlapi:::nhl_url_standings(seasons = 2015:2016) nhlapi:::nhl_url_standings( standingsType = "byDivision", expand = "standings.record" )
Create an NHL API URL for teams
nhl_url_teams(teamIds = NULL, params = NULL)
nhl_url_teams(teamIds = NULL, params = NULL)
teamIds |
|
params |
|
character()
, API URLs, same length as teamIds
or
length 1
if teamIds
is NULL
.
nhlapi:::nhl_url_teams() nhlapi:::nhl_url_teams(1:3)
nhlapi:::nhl_url_teams() nhlapi:::nhl_url_teams(1:3)
Create an NHL API URL for tournaments
nhl_url_tournaments(tournamentTypes, seasons = NULL, expand = NULL)
nhl_url_tournaments(tournamentTypes, seasons = NULL, expand = NULL)
tournamentTypes |
Those are exposed via shorthand functions |
seasons |
Alternatively, also accepts Some API endpoints, notably |
expand |
|
character()
, API URLs, same length as combinations of
tournamentTypes
, seasons
and expand
.
nhlapi:::nhl_url_tournaments("olympics") nhlapi:::nhl_url_tournaments("playoffs", 2015:2016) nhlapi:::nhl_url_tournaments("playoffs", 2015:2016, "round.series")
nhlapi:::nhl_url_tournaments("olympics") nhlapi:::nhl_url_tournaments("playoffs", 2015:2016) nhlapi:::nhl_url_tournaments("playoffs", 2015:2016, "round.series")
Create an NHL API URL for venues
nhl_url_venues(venueIds = NULL)
nhl_url_venues(venueIds = NULL)
venueIds |
|
character()
, API URLs, same length as venueIds
or
length 1
if venueIds
is NULL
.
nhlapi:::nhl_url_venues() nhlapi:::nhl_url_venues(5000:5006)
nhlapi:::nhl_url_venues() nhlapi:::nhl_url_venues(5000:5006)
Retrieve metadata on NHL venues from the API
nhl_venues(venueIds = NULL)
nhl_venues(venueIds = NULL)
venueIds |
|
data.frame
, with information on venues, one row per venue.
## Not run: # Get information on currently exposed venues nhl_venues() # Get information on 3 historical venues nhl_venues(5000:5006) ## End(Not run)
## Not run: # Get information on currently exposed venues nhl_venues() # Get information on 3 historical venues nhl_venues(5000:5006) ## End(Not run)
Take attributes with names specified by atrs
from object lst
and adds their value into columns with the same
name in df
.
util_attributes_to_cols(lst, df, atrs = c("url", "copyright"))
util_attributes_to_cols(lst, df, atrs = c("url", "copyright"))
lst |
|
df |
|
atrs |
|
data.frame
, df
with added columns.
"mm:ss"
character to numeric minutesConvert "mm:ss"
character to numeric minutes
util_convert_minsonice(chr, splitter = ":")
util_convert_minsonice(chr, splitter = ":")
chr |
|
splitter |
|
numeric()
, vector of times in minutes. Same length
as chr
.
nhlapi:::util_convert_minsonice(c("20:00", "1500:30"))
nhlapi:::util_convert_minsonice(c("20:00", "1500:30"))
sysdata.rda
fileGenerate the sysdata.rda
file
util_generate_sysdata(playerIds = 8444849L:8490000L, tgtPath = "sysdata.rda")
util_generate_sysdata(playerIds = 8444849L:8490000L, tgtPath = "sysdata.rda")
playerIds |
|
tgtPath |
|
data.frame
, with player name hashes and ids.
Take attributes with names specified by atrs
from object src
and add them as the same attributes to tgt
.
util_inherit_attributes(src, tgt, atrs = c("url", "copyright"))
util_inherit_attributes(src, tgt, atrs = c("url", "copyright"))
src |
|
tgt |
|
atrs |
|
object
, same as tgt
with attributes added.
Using a table of hashed names and ids, get a player id based on the name.
util_map_player_id(x, map = getOption("nhlapi_player_map"))
util_map_player_id(x, map = getOption("nhlapi_player_map"))
x |
|
map |
|
integer(1)
, id of the player or NA_integer
if not found.
nhlapi:::util_map_player_id( "Joe Sakic", data.frame( nameMd5 = "9d2a915c8610dbc524c1bc800e010fcc", id = 19L, stringsAsFactors = FALSE ) )
nhlapi:::util_map_player_id( "Joe Sakic", data.frame( nameMd5 = "9d2a915c8610dbc524c1bc800e010fcc", id = 19L, stringsAsFactors = FALSE ) )
Retrieve a player ids from their names
util_map_player_ids(playerNames, map = getOption("nhlapi_player_map"))
util_map_player_ids(playerNames, map = getOption("nhlapi_player_map"))
playerNames |
|
map |
|
integer()
, named vector of player ids,
'NA_integer“ for those names where id was not
found. In case a player name has multiple ids,
all of them are returned.
nhlapi:::util_map_player_ids( c("Joe SAKIC", "peter Forsberg", "test") )
nhlapi:::util_map_player_ids( c("Joe SAKIC", "peter Forsberg", "test") )
Writes x
to a temporary file
using writeChar()
and computes the md5sum()
on that file, removing the file afterwards.
util_md5sum_str(x)
util_md5sum_str(x)
x |
|
character(1)
, MD5 hash of a text file
created from x
using writeChar()
.
nhlapi:::util_md5sum_str("test")
nhlapi:::util_md5sum_str("test")
Prepare player ids based on player names
util_prepare_player_ids(playerNames, map = getOption("nhlapi_player_map"))
util_prepare_player_ids(playerNames, map = getOption("nhlapi_player_map"))
playerNames |
|
map |
|
integer()
, named vector of found valid player
ids, those not found omitted.
nhlapi:::util_prepare_player_ids(c("joe sakic", "fake player"))
nhlapi:::util_prepare_player_ids(c("joe sakic", "fake player"))
Removes the element named el
from x
if
present and keeps the information as an equally named
attribute.
util_process_copyright(x, el = "copyright")
util_process_copyright(x, el = "copyright")
x |
|
el |
|
list
, with the el
element removed and added
as attribute, if it is present in x
. Unchanged x
otherwise.
"mm:ss"
to numeric minutesConvert time columns from "mm:ss"
to numeric minutes
util_process_minsonice(df, patt = "timeOn|TimeOn")
util_process_minsonice(df, patt = "timeOn|TimeOn")
df |
|
patt |
|
data.frame
, with time columns converted from
"mm:ss"
characters to numeric minutes.
rbind
multiple data.framesAttempts to replace do.call(rbind, lst)
taking into consideration that some data frames in
lst
can have missing columns. Those are filled by
NA
values.
util_rbindlist(lst, fill = TRUE)
util_rbindlist(lst, fill = TRUE)
lst |
|
fill |
|
data.frame
, the elements of lst
, rbind
-ed into one.
nhlapi:::util_rbindlist(list( datasets::mtcars[1, 2:3], datasets::mtcars[2, 4:5] ))
nhlapi:::util_rbindlist(list( datasets::mtcars[1, 2:3], datasets::mtcars[2, 4:5] ))
nhl_get_data
Report errors encountered during nhl_get_data
util_report_get_data_errors(x, reporter = log_e, ...)
util_report_get_data_errors(x, reporter = log_e, ...)
x |
|
reporter |
|
... |
further arguments passed to |
character()
, URLs for which the retrieval
resulted in an error, invisibly. Optional side-effects.
## Not run: # Write errors to a temporary text file tmpFile <- tempfile() util_report_get_data_errors( nhl_get_data(nhl_url_players(c("none", "8451101", "some"))), reporter = writeLines, con = tmpFile ) ## End(Not run)
## Not run: # Write errors to a temporary text file tmpFile <- tempfile() util_report_get_data_errors( nhl_get_data(nhl_url_players(c("none", "8451101", "some"))), reporter = writeLines, con = tmpFile ) ## End(Not run)