diff --git a/NAMESPACE b/NAMESPACE index e715da06..2eb98ff6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -110,6 +110,7 @@ export(nba_drafthistory) export(nba_fantasywidget) export(nba_franchisehistory) export(nba_franchiseleaders) +export(nba_franchiseleaderswrank) export(nba_franchiseplayers) export(nba_gamerotation) export(nba_glalumboxscoresimilarityscore) @@ -143,6 +144,8 @@ export(nba_leagueplayerondetails) export(nba_leagueseasonmatchups) export(nba_leaguestandings) export(nba_leaguestandingsv3) +export(nba_live_boxscore) +export(nba_live_pbp) export(nba_matchupsrollup) export(nba_pbp) export(nba_pbps) @@ -181,6 +184,7 @@ export(nba_scoreboardv2) export(nba_shotchartdetail) export(nba_shotchartleaguewide) export(nba_shotchartlineupdetail) +export(nba_synergyplaytypes) export(nba_teamdashboardbyclutch) export(nba_teamdashboardbygamesplits) export(nba_teamdashboardbygeneralsplits) @@ -206,6 +210,7 @@ export(nba_teamplayeronoffsummary) export(nba_teamvsplayer) export(nba_teamyearbyyearstats) export(nba_videodetails) +export(nba_videodetailsasset) export(nba_videoevents) export(nba_videostatus) export(nba_winprobabilitypbp) diff --git a/NEWS.md b/NEWS.md index d9ec5c14..7f6d9052 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,11 @@ # **hoopR 1.9.1.9000** - Add proxy rlang dots option for passing httr::use_proxy() option to `nba_*()` functions - ```nba_shotchartlineupdetail()``` function added. +- ```nba_synergyplaytypes()``` function added. +- ```nba_live_pbp()``` function added. +- ```nba_live_boxscore()``` function added. +- ```nba_franchiseleaderswrank()``` function added. +- ```nba_videodetailsasset()``` function added. # **hoopR 1.9.1** - Updates under-the-hood urls to the ESPN site API v2 summary endpoints diff --git a/R/nba_stats_boxscore.R b/R/nba_stats_boxscore.R index 01b03694..e1b04070 100644 --- a/R/nba_stats_boxscore.R +++ b/R/nba_stats_boxscore.R @@ -1,10 +1,10 @@ #' **Get NBA Stats API Boxscore Traditional V2** -#' @name bs_trad_v2 +#' @name nba_boxscoretraditionalv2 NULL #' @title #' **Get NBA Stats API Boxscore Traditional V2** -#' @rdname bs_trad_v2 +#' @rdname nba_boxscoretraditionalv2 #' @author Saiem Gilani #' @param game_id Game ID #' @param start_period start_period @@ -61,11 +61,11 @@ nba_boxscoretraditionalv2 <- function( } #' **Get NBA Stats API Boxscore Advanced V2** -#' @name bs_adv_v2 +#' @name nba_boxscoreadvancedv2 NULL #' @title #' **Get NBA Stats API Boxscore Advanced V2** -#' @rdname bs_adv_v2 +#' @rdname nba_boxscoreadvancedv2 #' @author Saiem Gilani #' @param game_id Game ID #' @param start_period start_period @@ -124,11 +124,11 @@ nba_boxscoreadvancedv2 <- function( } #' **Get NBA Stats API Boxscore Defensive** -#' @name bs_defensive +#' @name nba_boxscoredefensive NULL #' @title #' **Get NBA Stats API Boxscore Defensive** -#' @rdname bs_defensive +#' @rdname nba_boxscoredefensive #' @author Saiem Gilani #' @param game_id Game ID #' @param ... Additional arguments passed to an underlying function like httr. @@ -170,11 +170,11 @@ nba_boxscoredefensive <- function( } #' **Get NBA Stats API Boxscore Four Factors V2** -#' @name bs_ff_v2 +#' @name nba_boxscorefourfactorsv2 NULL #' @title #' **Get NBA Stats API Boxscore Four Factors V2** -#' @rdname bs_ff_v2 +#' @rdname nba_boxscorefourfactorsv2 #' @author Saiem Gilani #' @param game_id Game ID #' @param start_period start_period @@ -231,11 +231,11 @@ nba_boxscorefourfactorsv2 <- function( } #' **Get NBA Stats API Boxscore Misc V2** -#' @name bs_misc_v2 +#' @name nba_boxscoremiscv2 NULL #' @title #' **Get NBA Stats API Boxscore Misc V2** -#' @rdname bs_misc_v2 +#' @rdname nba_boxscoremiscv2 #' @author Saiem Gilani #' @param game_id Game ID #' @param start_period start_period @@ -292,11 +292,11 @@ nba_boxscoremiscv2 <- function( } #' **Get NBA Stats API Boxscore Scoring V2** -#' @name bs_scoring_v2 +#' @name nba_boxscorescoringv2 NULL #' @title #' **Get NBA Stats API Boxscore Scoring V2** -#' @rdname bs_scoring_v2 +#' @rdname nba_boxscorescoringv2 #' @author Saiem Gilani #' @param game_id Game ID #' @param start_period start_period @@ -353,11 +353,11 @@ nba_boxscorescoringv2 <- function( } #' **Get NBA Stats API Boxscore Usage V2** -#' @name bs_usage_v2 +#' @name nba_boxscoreusagev2 NULL #' @title #' **Get NBA Stats API Boxscore Usage V2** -#' @rdname bs_usage_v2 +#' @rdname nba_boxscoreusagev2 #' @author Saiem Gilani #' @param game_id Game ID #' @param start_period start_period @@ -414,11 +414,11 @@ nba_boxscoreusagev2 <- function( } #' **Get NBA Stats API Boxscore Summary V2** -#' @name bs_summary_v2 +#' @name nba_boxscoresummaryv2 NULL #' @title #' **Get NBA Stats API Boxscore Summary V2** -#' @rdname bs_summary_v2 +#' @rdname nba_boxscoresummaryv2 #' @author Saiem Gilani #' @param game_id Game ID #' @param ... Additional arguments passed to an underlying function like httr. @@ -460,11 +460,11 @@ nba_boxscoresummaryv2 <- function( } #' **Get NBA Stats API Boxscore Matchups** -#' @name bs_match +#' @name nba_boxscorematchups NULL #' @title #' **Get NBA Stats API Boxscore Matchups** -#' @rdname bs_match +#' @rdname nba_boxscorematchups #' @author Saiem Gilani #' @param game_id Game ID #' @param version Boxscore Matchups version ("v2" available from 2016-17 onwards) @@ -511,11 +511,11 @@ nba_boxscorematchups <- function( } #' **Get NBA Stats API Boxscore Player Tracking V2** -#' @name bs_pt_v2 +#' @name nba_boxscoreplayertrackv2 NULL #' @title #' **Get NBA Stats API Boxscore Player Tracking V2** -#' @rdname bs_pt_v2 +#' @rdname nba_boxscoreplayertrackv2 #' @author Saiem Gilani #' @param game_id Game ID #' @param ... Additional arguments passed to an underlying function like httr. @@ -557,11 +557,11 @@ nba_boxscoreplayertrackv2 <- function( } #' **Get NBA Stats API Hustle Stats Boxscore** -#' @name hustle_bs +#' @name nba_hustlestatsboxscore NULL #' @title #' **Get NBA Stats API Hustle Stats Boxscore** -#' @rdname hustle_bs +#' @rdname nba_hustlestatsboxscore #' @author Saiem Gilani #' @param game_id Game ID #' @param ... Additional arguments passed to an underlying function like httr. @@ -603,11 +603,11 @@ nba_hustlestatsboxscore <- function( } #' **Get NBA Stats API Game Rotation** -#' @name game_rotation +#' @name nba_gamerotation NULL #' @title #' **Get NBA Stats API Game Rotation** -#' @rdname game_rotation +#' @rdname nba_gamerotation #' @author Saiem Gilani #' @param game_id Game ID #' @param league_id League ID @@ -663,11 +663,11 @@ nba_gamerotation <- function( } #' **Get NBA Stats API Boxscore Similarity Score** -#' @name bs_similarity +#' @name nba_boxscoresimilarityscore NULL #' @title #' **Get NBA Stats API Boxscore Similarity Score** -#' @rdname bs_similarity +#' @rdname nba_boxscoresimilarityscore #' @author Saiem Gilani #' @param person_1_id person_1_id #' @param person_1_league_id person_1_league_id @@ -726,11 +726,11 @@ nba_boxscoresimilarityscore <- function( } #' **Get NBA Stats API G-League Alum Boxscore Similarity Score** -#' @name gl_bs_similarity +#' @name nba_glalumboxscoresimilarityscore NULL #' @title #' **Get NBA Stats API G-League Alum Boxscore Similarity Score** -#' @rdname gl_bs_similarity +#' @rdname nba_glalumboxscoresimilarityscore #' @author Saiem Gilani #' @param person_1_id person_1_id #' @param person_1_league_id person_1_league_id diff --git a/R/nba_stats_cume.R b/R/nba_stats_cume.R index 638d8443..c725cd4f 100644 --- a/R/nba_stats_cume.R +++ b/R/nba_stats_cume.R @@ -1,9 +1,9 @@ #' **Get NBA Stats API Cumulative Player Stats** -#' @name cumestatsplayer +#' @name nba_cumestatsplayer NULL #' @title #' **Get NBA Stats API Cumulative Player Stats** -#' @rdname cumestatsplayer +#' @rdname nba_cumestatsplayer #' @author Saiem Gilani #' @param game_ids game_ids #' @param league_id league_id @@ -17,6 +17,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [CUME Stats](https://www.nba.com/stats/cumestats) +#' ```r +#' nba_cumestatsplayer() +#' ``` nba_cumestatsplayer <- function( game_ids = '0022000756', @@ -57,11 +62,11 @@ nba_cumestatsplayer <- function( } #' **Get NBA Stats API Cumulative Player Game Stats** -#' @name cumestatsplayergames +#' @name nba_cumestatsplayergames NULL #' @title #' **Get NBA Stats API Cumulative Player Game Stats** -#' @rdname cumestatsplayergames +#' @rdname nba_cumestatsplayergames #' @author Saiem Gilani #' @param league_id league_id #' @param location location @@ -78,12 +83,17 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [CUME Stats](https://www.nba.com/stats/cumestats) +#' ```r +#' nba_cumestatsplayergames(player_id = '2544') +#' ``` nba_cumestatsplayergames <- function( league_id = '00', location = '', outcome = '', player_id = '2544', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', vs_conference = '', vs_division = '', @@ -123,11 +133,11 @@ nba_cumestatsplayergames <- function( } #' **Get NBA Stats API Cumulative Team Stats** -#' @name cumestatsteam +#' @name nba_cumestatsteam NULL #' @title #' **Get NBA Stats API Cumulative Team Stats** -#' @rdname cumestatsteam +#' @rdname nba_cumestatsteam #' @author Saiem Gilani #' @param game_ids game_ids #' @param league_id league_id @@ -140,12 +150,17 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [CUME Stats](https://www.nba.com/stats/cumestats) +#' ```r +#' nba_cumestatsteam() +#' ``` nba_cumestatsteam <- function( game_ids = '0022000756', league_id = '00', season = '2020-21', season_type = 'Regular Season', - team_id = '', + team_id = '1610612739', ...){ season_type <- gsub(' ','+',season_type) @@ -177,11 +192,11 @@ nba_cumestatsteam <- function( return(df_list) } #' **Get NBA Stats API Cumulative Team Game Stats** -#' @name cumestatsteamgames +#' @name nba_cumestatsteamgames NULL #' @title #' **Get NBA Stats API Cumulative Team Game Stats** -#' @rdname cumestatsteamgames +#' @rdname nba_cumestatsteamgames #' @author Saiem Gilani #' @param league_id league_id #' @param location location @@ -199,11 +214,16 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [CUME Stats](https://www.nba.com/stats/cumestats) +#' ```r +#' nba_cumestatsteamgames() +#' ``` nba_cumestatsteamgames <- function( league_id = '00', location = '', outcome = '', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_id = '', season_type = 'Regular Season', team_id = 1610612739, diff --git a/R/nba_stats_draft.R b/R/nba_stats_draft.R index 616f6c90..56a8efed 100644 --- a/R/nba_stats_draft.R +++ b/R/nba_stats_draft.R @@ -1,10 +1,10 @@ #' **Get NBA Stats API Draft Board** -#' @name dboard +#' @name nba_draftboard NULL #' @title #' **Get NBA Stats API Draft Board** -#' @rdname dboard +#' @rdname nba_draftboard #' @author Saiem Gilani #' @param league_id league_id #' @param college college @@ -20,13 +20,17 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_draftboard(season = most_recent_nba_season() - 1) +#' ``` nba_draftboard <- function( league_id = '00', college = '', overall_pick = '', round_pick = '', round_num = '', - season = '2019', + season = most_recent_nba_season() - 1, team_id = '', top_x = '', ...){ @@ -66,11 +70,11 @@ nba_draftboard <- function( #' **Get NBA Stats API Draft Combine Stats** -#' @name dcombine_stats +#' @name nba_draftcombinestats NULL #' @title #' **Get NBA Stats API Draft Combine Stats** -#' @rdname dcombine_stats +#' @rdname nba_draftcombinestats #' @author Saiem Gilani #' @param league_id league_id #' @param season_year season_year @@ -80,9 +84,13 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_draftcombinestats(season_year = most_recent_nba_season() - 1) +#' ``` nba_draftcombinestats <- function( league_id = '00', - season_year = '2020', + season_year = most_recent_nba_season() - 1, ...){ @@ -113,11 +121,11 @@ nba_draftcombinestats <- function( #' **Get NBA Stats API Draft Combine Drill Results** -#' @name dcombine_drill +#' @name nba_draftcombinedrillresults NULL #' @title #' **Get NBA Stats API Draft Combine Drill Results** -#' @rdname dcombine_drill +#' @rdname nba_draftcombinedrillresults #' @author Saiem Gilani #' @param league_id league_id #' @param season_year season_year @@ -127,9 +135,14 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Draft Combine](https://www.nba.com/stats/draft/combine) +#' ```r +#' nba_draftcombinedrillresults(season_year = most_recent_nba_season() - 1) +#' ``` nba_draftcombinedrillresults <- function( league_id = '00', - season_year = '2020', + season_year = most_recent_nba_season() - 1, ...){ @@ -161,11 +174,11 @@ nba_draftcombinedrillresults <- function( #' **Get NBA Stats API Draft Combine Non-Stationary Shooting** -#' @name dcombine_nsshooting +#' @name nba_draftcombinenonstationaryshooting NULL #' @title #' **Get NBA Stats API Draft Combine Non-Stationary Shooting** -#' @rdname dcombine_nsshooting +#' @rdname nba_draftcombinenonstationaryshooting #' @author Saiem Gilani #' @param league_id league_id #' @param season_year season_year @@ -175,9 +188,14 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Draft Combine Non-stationary Shooting](https://www.nba.com/stats/draft/combine-non-stationary) +#' ```r +#' nba_draftcombinenonstationaryshooting(season_year = most_recent_nba_season() - 1) +#' ``` nba_draftcombinenonstationaryshooting <- function( league_id = '00', - season_year = '2020', + season_year = most_recent_nba_season() - 1, ...){ @@ -209,11 +227,11 @@ nba_draftcombinenonstationaryshooting <- function( #' **Get NBA Stats API Draft Combine Player Anthropological Measurements** -#' @name dcombine_anthro +#' @name nba_draftcombineplayeranthro NULL #' @title #' **Get NBA Stats API Draft Combine Player Anthropological Measurements** -#' @rdname dcombine_anthro +#' @rdname nba_draftcombineplayeranthro #' @author Saiem Gilani #' @param league_id league_id #' @param season_year season_year @@ -223,9 +241,14 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Draft Combine Player Anthro](https://www.nba.com/stats/draft/combine) +#' ```r +#' nba_draftcombineplayeranthro(season_year = most_recent_nba_season() - 1) +#' ``` nba_draftcombineplayeranthro <- function( league_id = '00', - season_year = '2020', + season_year = most_recent_nba_season() - 1, ...){ @@ -255,11 +278,11 @@ nba_draftcombineplayeranthro <- function( } #' **Get NBA Stats API Draft Combine - Spot Shooting** -#' @name dcombine_sshooting +#' @name nba_draftcombinespotshooting NULL #' @title #' **Get NBA Stats API Draft Combine - Spot Shooting** -#' @rdname dcombine_sshooting +#' @rdname nba_draftcombinespotshooting #' @author Saiem Gilani #' @param league_id league_id #' @param season_year season_year @@ -269,9 +292,14 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Draft Combine Spot Shooting](https://www.nba.com/stats/draft/combine-spot-up) +#' ```r +#' nba_draftcombinespotshooting(season_year = most_recent_nba_season() - 1) +#' ``` nba_draftcombinespotshooting <- function( league_id = '00', - season_year = '2020', + season_year = most_recent_nba_season() - 1, ...){ @@ -303,7 +331,7 @@ nba_draftcombinespotshooting <- function( #' @title #' **Get NBA Stats API Draft History** -#' @rdname dhistory +#' @rdname nba_drafthistory #' @author Saiem Gilani #' @param league_id league_id #' @param college college @@ -319,13 +347,18 @@ nba_draftcombinespotshooting <- function( #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Draft History](https://www.nba.com/stats/draft/history) +#' ```r +#' nba_drafthistory(season = most_recent_nba_season() - 1) +#' ``` nba_drafthistory <- function( league_id = '00', college = '', overall_pick = '', round_pick = '', round_num = '', - season = '2019', + season = most_recent_nba_season() - 1, team_id = '', top_x = '', ...){ diff --git a/R/nba_stats_franchise.R b/R/nba_stats_franchise.R index 24270422..df396a31 100644 --- a/R/nba_stats_franchise.R +++ b/R/nba_stats_franchise.R @@ -1,9 +1,9 @@ #' **Get NBA Stats API Franchise Leaders** -#' @name franchiseleaders +#' @name nba_franchiseleaders NULL #' @title #' **Get NBA Stats API Franchise Leaders** -#' @rdname franchiseleaders +#' @rdname nba_franchiseleaders #' @author Saiem Gilani #' @param league_id league_id #' @param team_id team_id @@ -13,11 +13,15 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Franchise Leaders](https://www.nba.com/stats/team/1610612737/franchise-leaders) +#' ```r +#' nba_franchiseleaders(league_id = '00', team_id = '1610612739') +#' ``` nba_franchiseleaders <- function( league_id = '00', team_id = '1610612739', ...){ - season_type <- gsub(' ','+',season_type) version <- "franchiseleaders" endpoint <- nba_endpoint(version) @@ -44,13 +48,70 @@ nba_franchiseleaders <- function( return(df_list) } +#' **Get NBA Stats API Franchise Leaders with Rank** +#' @name nba_franchiseleaderswrank +NULL +#' @title +#' **Get NBA Stats API Franchise Leaders with Rank** +#' @rdname nba_franchiseleaderswrank +#' @author Saiem Gilani +#' @param league_id league_id +#' @param per_mode per_mode +#' @param season_type season_type +#' @param team_id team_id +#' @param ... Additional arguments passed to an underlying function like httr. +#' @return Returns a named list of data frames: FranchiseLeaderswRank +#' @importFrom jsonlite fromJSON toJSON +#' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble +#' @import rvest +#' @export +#' @details +#' [Franchise Players](https://www.nba.com/stats/team/1610612739/franchise-leaders) +#' ```r +#' nba_franchiseleaderswrank(league_id = '00', team_id = '1610612739') +#' nba_franchiseleaderswrank(league_id = '00', season_type = 'Playoffs', team_id = '1610612739') +#' ``` +nba_franchiseleaderswrank <- function( + league_id = '00', + per_mode = 'Totals', + season_type = 'Regular Season', + team_id = '1610612739', + ...){ + season_type <- gsub(' ','+',season_type) + version <- "franchiseleaderswrank" + endpoint <- nba_endpoint(version) + + full_url <- paste0(endpoint, + "?LeagueID=",league_id, + "&PerMode=", per_mode, + "&SeasonType=", season_type, + "&TeamID=",team_id) + + tryCatch( + expr = { + + resp <- request_with_proxy(url = full_url, ...) + + df_list <- nba_stats_map_result_sets(resp) + + }, + error = function(e) { + message(glue::glue("{Sys.time()}: Invalid arguments or no franchise players data available for {team_id}!")) + }, + warning = function(w) { + }, + finally = { + } + ) + return(df_list) +} #' **Get NBA Stats API Franchise Players** -#' @name franchiseplayers +#' @name nba_franchiseplayers NULL #' @title #' **Get NBA Stats API Franchise Players** -#' @rdname franchiseplayers +#' @rdname nba_franchiseplayers #' @author Saiem Gilani #' @param league_id league_id #' @param per_mode per_mode @@ -62,6 +123,12 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Franchise Players](https://www.nba.com/stats/team/1610612739/franchise-leaders) +#' ```r +#' nba_franchiseplayers(league_id = '00', team_id = '1610612739') +#' nba_franchiseplayers(league_id = '00', season_type = 'Playoffs', team_id = '1610612739') +#' ``` nba_franchiseplayers <- function( league_id = '00', per_mode = 'Totals', @@ -99,11 +166,11 @@ nba_franchiseplayers <- function( #' **Get NBA Stats API Franchise History** -#' @name franchisehistory +#' @name nba_franchisehistory NULL #' @title #' **Get NBA Stats API Franchise History** -#' @rdname franchisehistory +#' @rdname nba_franchisehistory #' @author Saiem Gilani #' @param league_id league_id #' @param ... Additional arguments passed to an underlying function like httr. @@ -112,6 +179,14 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Franchise History](https://www.nba.com/stats/history) +#' ```r +#' nba_franchisehistory(league_id = '00') +#' nba_franchisehistory(league_id = '01') +#' nba_franchisehistory(league_id = '10') +#' nba_franchisehistory(league_id = '20') +#' ``` nba_franchisehistory <- function( league_id = '00', ...){ diff --git a/R/nba_stats_hustle.R b/R/nba_stats_hustle.R index 7bcd82ad..25dfb3fb 100644 --- a/R/nba_stats_hustle.R +++ b/R/nba_stats_hustle.R @@ -1,9 +1,9 @@ #' **Get NBA Stats API League Hustle Stats Player** -#' @name hustle_p +#' @name nba_leaguehustlestatsplayer NULL #' @title #' **Get NBA Stats API League Hustle Stats Player** -#' @rdname hustle_p +#' @rdname nba_leaguehustlestatsplayer #' @author Saiem Gilani #' @param college college #' @param conference conference @@ -37,6 +37,13 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Hustle Stats](https://www.nba.com/stats/players/hustle) +#' ```r +#' nba_leaguehustlestatsplayer(league_id = '00') +#' nba_leaguehustlestatsplayer(league_id = '00', team_id = '1610612761') +#' +#' ``` nba_leaguehustlestatsplayer <- function( college = '', conference = '', @@ -57,7 +64,7 @@ nba_leaguehustlestatsplayer <- function( per_mode = 'Totals', player_experience = '', player_position = '', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '', @@ -116,11 +123,11 @@ nba_leaguehustlestatsplayer <- function( } #' **Get NBA Stats API League Hustle Stats Player Leaders** -#' @name hustle_pl +#' @name nba_leaguehustlestatsplayerleaders NULL #' @title #' **Get NBA Stats API League Hustle Stats Player Leaders** -#' @rdname hustle_pl +#' @rdname nba_leaguehustlestatsplayerleaders #' @author Saiem Gilani #' @param college college #' @param conference conference @@ -154,6 +161,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Hustle Stats Leaders](https://www.nba.com/stats/players/hustle-leaders) +#' ```r +#' nba_leaguehustlestatsplayerleaders(league_id = '00') +#' ``` nba_leaguehustlestatsplayerleaders <- function( college = '', conference = '', @@ -174,7 +186,7 @@ nba_leaguehustlestatsplayerleaders <- function( per_mode = 'Totals', player_experience = '', player_position = '', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '', @@ -233,11 +245,11 @@ nba_leaguehustlestatsplayerleaders <- function( } #' **Get NBA Stats API League Hustle Stats Team** -#' @name hustle_t +#' @name nba_leaguehustlestatsteam NULL #' @title #' **Get NBA Stats API League Hustle Stats Team** -#' @rdname hustle_t +#' @rdname nba_leaguehustlestatsteam #' @author Saiem Gilani #' @param college college #' @param conference conference @@ -271,6 +283,12 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Hustle Stats](https://www.nba.com/stats/teams/hustle) +#' ```r +#' nba_leaguehustlestatsteam(league_id = '00') +#' +#' ``` nba_leaguehustlestatsteam <- function( college = '', conference = '', @@ -291,7 +309,7 @@ nba_leaguehustlestatsteam <- function( per_mode = 'Totals', player_experience = '', player_position = '', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '', @@ -349,11 +367,11 @@ nba_leaguehustlestatsteam <- function( return(df_list) } #' **Get NBA Stats API League Hustle Stats Team Leaders** -#' @name hustle_tl +#' @name nba_leaguehustlestatsteamleaders NULL #' @title #' **Get NBA Stats API League Hustle Stats Team Leaders** -#' @rdname hustle_tl +#' @rdname nba_leaguehustlestatsteamleaders #' @author Saiem Gilani #' @param college college #' @param conference conference @@ -387,6 +405,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Hustle Stats Leaders](https://www.nba.com/stats/teams/hustle-leaders) +#' ```r +#' nba_leaguehustlestatsteamleaders(league_id = '00') +#' ``` nba_leaguehustlestatsteamleaders <- function( college = '', conference = '', @@ -407,7 +430,7 @@ nba_leaguehustlestatsteamleaders <- function( per_mode = 'Totals', player_experience = '', player_position = '', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '', diff --git a/R/nba_stats_leaders.R b/R/nba_stats_leaders.R index d8417b11..296e9998 100644 --- a/R/nba_stats_leaders.R +++ b/R/nba_stats_leaders.R @@ -1,9 +1,9 @@ #' **Get NBA Stats API All-time Leaders Grid** -#' @name alltime +#' @name nba_alltimeleadersgrids NULL #' @title #' **Get NBA Stats API All-time Leaders Grid** -#' @rdname alltime +#' @rdname nba_alltimeleadersgrids #' @author Saiem Gilani #' @param season_type Season Type - Regular Season, Playoffs, All-Star #' @param per_mode Per Mode - PerGame, Totals @@ -16,6 +16,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_alltimeleadersgrids(league_id = '00') +#' ``` nba_alltimeleadersgrids <- function( league_id = '00', @@ -28,10 +32,10 @@ nba_alltimeleadersgrids <- function( endpoint <- nba_endpoint(version) full_url <- paste0(endpoint, - "?LeagueID=",league_id, - "&PerMode=",per_mode, - "&SeasonType=",season_type, - "&TopX=",top_x) + "?LeagueID=", league_id, + "&PerMode=", per_mode, + "&SeasonType=", season_type, + "&TopX=", top_x) tryCatch( expr = { @@ -54,11 +58,11 @@ nba_alltimeleadersgrids <- function( #' **Get NBA Stats API Assist Leaders** -#' @name assists +#' @name nba_assistleaders NULL #' @title #' **Get NBA Stats API Assist Leaders** -#' @rdname assists +#' @rdname nba_assistleaders #' @author Saiem Gilani #' @param season Season - format 2020-21 #' @param season_type Season Type - Regular Season, Playoffs, All-Star @@ -71,12 +75,16 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export - +#' @details +#' ```r +#' nba_assistleaders(league_id = '00', player_or_team = "Player") +#' nba_assistleaders(league_id = '00', player_or_team = "Team") +#' ``` nba_assistleaders <- function( league_id = '00', per_mode = 'PerGame', player_or_team = 'Team', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', ...){ @@ -85,11 +93,11 @@ nba_assistleaders <- function( endpoint <- nba_endpoint(version) full_url <- paste0(endpoint, - "?LeagueID=",league_id, - "&PerMode=",per_mode, - "&PlayerOrTeam=",player_or_team, - "&Season=",season, - "&SeasonType=",season_type) + "?LeagueID=", league_id, + "&PerMode=", per_mode, + "&PlayerOrTeam=", player_or_team, + "&Season=", season, + "&SeasonType=", season_type) tryCatch( expr = { @@ -110,11 +118,11 @@ nba_assistleaders <- function( return(df_list) } #' **Get NBA Stats API Assist Tracker** -#' @name assist_tracker +#' @name nba_assisttracker NULL #' @title #' **Get NBA Stats API Assist Tracker** -#' @rdname assist_tracker +#' @rdname nba_assisttracker #' @author Saiem Gilani #' @param season Season - format 2020-21 #' @param season_type Season Type - Regular Season, Playoffs, All-Star @@ -126,10 +134,14 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_assisttracker(league_id = '00') +#' ``` nba_assisttracker <- function( league_id = '00', per_mode = 'PerGame', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', ...){ @@ -138,10 +150,10 @@ nba_assisttracker <- function( endpoint <- nba_endpoint(version) full_url <- paste0(endpoint, - "?LeagueID=",league_id, - "&PerMode=",per_mode, - "&Season=",season, - "&SeasonType=",season_type) + "?LeagueID=", league_id, + "&PerMode=", per_mode, + "&Season=", season, + "&SeasonType=", season_type) tryCatch( expr = { @@ -163,11 +175,11 @@ nba_assisttracker <- function( } #' **Get NBA Stats API Homepage Leaders** -#' @name homepageleaders +#' @name nba_homepageleaders NULL #' @title #' **Get NBA Stats API Homepage Leaders** -#' @rdname homepageleaders +#' @rdname nba_homepageleaders #' @author Saiem Gilani #' @param game_scope Game Scope - Season, Last 10, ,Yesterday, Finals #' @param season Season - format 2020-21 @@ -182,13 +194,17 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export - +#' @details +#' ```r +#' nba_homepageleaders(league_id = '00', player_or_team = "Player") +#' nba_homepageleaders(league_id = '00', player_or_team = "Team") +#' ``` nba_homepageleaders <- function( league_id = '00', game_scope = 'Season', player_or_team = 'Team', player_scope = 'All Players', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', stat_category = 'Points', ...){ @@ -228,11 +244,11 @@ nba_homepageleaders <- function( #' **Get NBA Stats API HomepageV2 Leaders** -#' @name homepagev2 +#' @name nba_homepagev2 NULL #' @title #' **Get NBA Stats API HomepageV2 Leaders** -#' @rdname homepagev2 +#' @rdname nba_homepagev2 #' @author Saiem Gilani #' @param game_scope Game Scope - Season, Last 10, ,Yesterday, Finals #' @param season Season - format 2020-21 @@ -248,13 +264,18 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_homepagev2(league_id = '00', player_or_team = "Player") +#' nba_homepagev2(league_id = '00', player_or_team = "Team") +#' ``` nba_homepagev2 <- function( league_id = '00', game_scope = 'Season', player_or_team = 'Team', player_scope = 'All Players', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', stat_type = 'Traditional', ...){ @@ -294,11 +315,11 @@ nba_homepagev2 <- function( #' **Get NBA Stats API Leaders Tiles** -#' @name leaderstiles +#' @name nba_leaderstiles NULL #' @title #' **Get NBA Stats API Leaders Tiles** -#' @rdname leaderstiles +#' @rdname nba_leaderstiles #' @author Saiem Gilani #' @param game_scope Game Scope - Season, Last 10, ,Yesterday, Finals #' @param season Season - format 2020-21 @@ -313,13 +334,18 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_leaderstiles(league_id = '00', player_or_team = "Player") +#' nba_leaderstiles(league_id = '00', player_or_team = "Team") +#' ``` nba_leaderstiles <- function( league_id = '00', game_scope = 'Season', player_or_team = 'Team', player_scope = 'All Players', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', stat = 'PTS', ...){ @@ -359,11 +385,11 @@ nba_leaderstiles <- function( #' **Get NBA Stats API Defense Hub** -#' @name defensehub +#' @name nba_defensehub NULL #' @title #' **Get NBA Stats API Defense Hub** -#' @rdname defensehub +#' @rdname nba_defensehub #' @author Saiem Gilani #' @param game_scope Game Scope - Season, Last 10, ,Yesterday, Finals #' @param season Season - format 2020-21 @@ -378,13 +404,18 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_defensehub(league_id = '00', player_or_team = "Player") +#' nba_defensehub(league_id = '00', player_or_team = "Team") +#' ``` nba_defensehub <- function( league_id = '00', game_scope = 'Season', player_or_team = 'Team', player_scope = 'All Players', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', ...){ @@ -424,11 +455,11 @@ nba_defensehub <- function( #' **Get NBA Stats API League Leaders** -#' @name leagueleaders +#' @name nba_leagueleaders NULL #' @title #' **Get NBA Stats API League Leaders** -#' @rdname leagueleaders +#' @rdname nba_leagueleaders #' @author Saiem Gilani #' @param active_flag Active Flag #' @param season Season - format 2020-21 @@ -443,13 +474,18 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [League Leaders](https://www.nba.com/stats/leaders) +#' ```r +#' nba_leagueleaders(league_id = '00') +#' ``` nba_leagueleaders <- function( active_flag = '', league_id = '00', per_mode = 'Totals', scope = 'S', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', stat_category = 'PTS', ...){ @@ -473,7 +509,16 @@ nba_leagueleaders <- function( resp <- request_with_proxy(url = full_url, ...) - df_list <- nba_stats_map_result_sets(resp) + df_list <- purrr::map(1:length(resp$resultSet$name), function(x){ + data <- resp$resultSet$rowSet %>% + data.frame(stringsAsFactors = F) %>% + dplyr::as_tibble() + + json_names <- resp$resultSet$headers + colnames(data) <- json_names + return(data) + }) + names(df_list) <- resp$resultSet$name }, error = function(e) { diff --git a/R/nba_stats_league.R b/R/nba_stats_league.R index 095a4be3..cfd4529c 100644 --- a/R/nba_stats_league.R +++ b/R/nba_stats_league.R @@ -1,9 +1,9 @@ #' **Get NBA Stats API League Game Log** -#' @name l_gamelog +#' @name nba_leaguegamelog NULL #' @title #' **Get NBA Stats API League Game Log** -#' @rdname l_gamelog +#' @rdname nba_leaguegamelog #' @author Saiem Gilani #' @param counter counter #' @param date_from date_from @@ -20,16 +20,21 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player/Team Boxscores](https://www.nba.com/stats/players/boxscores) +#' ```r +#' nba_leaguegamelog(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguegamelog <- function( counter = 0, date_from = '', date_to = '', direction = 'ASC', - league_id='00', - player_or_team='T', - season='2020-21', - season_type='Regular Season', - sorter='DATE', + league_id = '00', + player_or_team = 'T', + season = year_to_season(most_recent_nba_season() - 1), + season_type = 'Regular Season', + sorter = 'DATE', ...){ season_type <- gsub(' ','+',season_type) version <- "leaguegamelog" @@ -67,11 +72,11 @@ nba_leaguegamelog <- function( #' **Get NBA Stats API League Standings** -#' @name l_standings +#' @name nba_leaguestandings NULL #' @title #' **Get NBA Stats API League Standings** -#' @rdname l_standings +#' @rdname nba_leaguestandings #' @author Saiem Gilani #' @param league_id league_id #' @param season season @@ -83,11 +88,16 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [League Standings](https://www.nba.com/standings) +#' ```r +#' nba_leaguestandings(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguestandings <- function( - league_id='00', - season='2020-21', - season_type='Regular Season', - season_year='', + league_id = '00', + season = year_to_season(most_recent_nba_season() - 1), + season_type = 'Regular Season', + season_year = '', ...){ season_type <- gsub(' ','+',season_type) version <- "leaguestandings" @@ -120,11 +130,11 @@ nba_leaguestandings <- function( #' **Get NBA Stats API League Standings V3** -#' @name l_standingsv3 +#' @name nba_leaguestandingsv3 NULL #' @title #' **Get NBA Stats API League Standings V3** -#' @rdname l_standingsv3 +#' @rdname nba_leaguestandingsv3 #' @author Saiem Gilani #' @param league_id league_id #' @param season season @@ -136,11 +146,16 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [League Standings](https://www.nba.com/standings) +#' ```r +#' nba_leaguestandingsv3(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguestandingsv3 <- function( - league_id='00', - season='2020-21', - season_type='Regular Season', - season_year='', + league_id = '00', + season = year_to_season(most_recent_nba_season() - 1), + season_type = 'Regular Season', + season_year = '', ...){ season_type <- gsub(' ','+',season_type) version <- "leaguestandingsv3" @@ -173,11 +188,11 @@ nba_leaguestandingsv3 <- function( #' **Get NBA Stats API Playoff Picture** -#' @name po_picture +#' @name nba_playoffpicture NULL #' @title #' **Get NBA Stats API Playoff Picture** -#' @rdname po_picture +#' @rdname nba_playoffpicture #' @author Saiem Gilani #' @param league_id league_id #' @param season_id season_id @@ -190,8 +205,8 @@ NULL #' @import rvest #' @export nba_playoffpicture <- function( - league_id='00', - season_id='22020', + league_id = '00', + season_id = '22022', ...){ version <- "playoffpicture" @@ -222,11 +237,11 @@ nba_playoffpicture <- function( #' **Get NBA Stats API League Game Streak Finder** -#' @name lg_streak +#' @name nba_leaguegamefinder NULL #' @title #' **Get NBA Stats API League Game Streak Finder** -#' @rdname lg_streak +#' @rdname nba_leaguegamefinder #' @author Saiem Gilani #' @param conference conference #' @param date_from date_from @@ -322,6 +337,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_leaguegamefinder(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguegamefinder <- function( conference = '', date_from = '', @@ -402,7 +421,7 @@ nba_leaguegamefinder <- function( player_id = '', player_or_team = 'T', rookie_year = '', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', starter_bench = '', diff --git a/R/nba_stats_league_dash.R b/R/nba_stats_league_dash.R index a163571d..1b248d11 100644 --- a/R/nba_stats_league_dash.R +++ b/R/nba_stats_league_dash.R @@ -1,11 +1,11 @@ #' **Get NBA Stats API League Dashboard Player Tracking - Opponent Shots** -#' @name ld_oppptshot +#' @name nba_leaguedashoppptshot NULL #' @title #' **Get NBA Stats API League Dashboard Player Tracking - Opponent Shots** -#' @rdname ld_oppptshot +#' @rdname nba_leaguedashoppptshot #' @author Saiem Gilani #' @param close_def_dist_range close_def_dist_range #' @param conference conference @@ -43,6 +43,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Opponent Shots - General](https://www.nba.com/stats/teams/opponent-shots-general) +#' ```r +#' nba_leaguedashoppptshot(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguedashoppptshot <- function( close_def_dist_range = '', conference = '', @@ -51,29 +56,29 @@ nba_leaguedashoppptshot <- function( division = '', dribble_range = '', game_segment = '', - general_range='', - last_n_games=0, - league_id='00', - location='', - measure_type='Base', - month=0, - opponent_team_id=0, - outcome='', - po_round='', - pace_adjust='N', - per_mode='Totals', - period=0, - plus_minus='N', - rank='N', - season='2020-21', - season_segment='', - season_type='Regular Season', - shot_clock_range='', + general_range = '', + last_n_games = 0, + league_id = '00', + location = '', + measure_type = 'Base', + month = 0, + opponent_team_id = 0, + outcome = '', + po_round = '', + pace_adjust = 'N', + per_mode = 'Totals', + period = 0, + plus_minus = 'N', + rank = 'Y', + season = year_to_season(most_recent_nba_season() - 1), + season_segment = '', + season_type = 'Regular Season', + shot_clock_range = '', shot_dist_range = '', - team_id='', + team_id = '', touch_time_range = '', - vs_conference='', - vs_division='', + vs_conference = '', + vs_division = '', ...){ season_type <- gsub(' ','+',season_type) version <- "leaguedashoppptshot" @@ -116,16 +121,8 @@ nba_leaguedashoppptshot <- function( resp <- request_with_proxy(url = full_url, ...) - df_list <- purrr::map(1:length(resp$resultSets$name), function(x){ - data <- resp$resultSets$rowSet[[x]] %>% - data.frame(stringsAsFactors = F) %>% - as_tibble() + df_list <- nba_stats_map_result_sets(resp) - json_names <- resp$resultSets$headers[[x]] - colnames(data) <- json_names - return(data) - }) - names(df_list) <- resp$resultSets$name }, error = function(e) { message(glue::glue("{Sys.time()}: Invalid arguments or no league dashboard player-tracking oppponent shooting data for {season} available!")) @@ -140,11 +137,11 @@ nba_leaguedashoppptshot <- function( #' **Get NBA Stats API League Dashboard Player Biographical Stats** -#' @name ld_pbiostats +#' @name nba_leaguedashplayerbiostats NULL #' @title #' **Get NBA Stats API League Dashboard Player Biographical Stats** -#' @rdname ld_pbiostats +#' @rdname nba_leaguedashplayerbiostats #' @author Saiem Gilani #' @param college college #' @param conference conference @@ -184,6 +181,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Bio Stats](https://www.nba.com/stats/players/bio) +#' ```r +#' nba_leaguedashplayerbiostats(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguedashplayerbiostats <- function( college = '', conference = '', @@ -194,29 +196,29 @@ nba_leaguedashplayerbiostats <- function( draft_pick = '', draft_year = '', game_segment = '', - game_scope='', + game_scope = '', height = '', - last_n_games=0, - league_id='00', - location='', - month=0, - opponent_team_id=0, - outcome='', - po_round='', - per_mode='Totals', - period='', - player_experience='', - player_position='', - season='2020-21', - season_segment='', - season_type='Regular Season', - shot_clock_range='', + last_n_games = 0, + league_id = '00', + location = '', + month = 0, + opponent_team_id = 0, + outcome = '', + po_round = '', + per_mode = 'Totals', + period = '', + player_experience = '', + player_position = '', + season = year_to_season(most_recent_nba_season() - 1), + season_segment = '', + season_type = 'Regular Season', + shot_clock_range = '', starter_bench = '', - team_id='', + team_id = '', touch_time_range = '', - vs_conference='', - vs_division='', - weight='', + vs_conference = '', + vs_division = '', + weight = '', ...){ season_type <- gsub(' ','+',season_type) version <- "leaguedashplayerbiostats" @@ -261,16 +263,8 @@ nba_leaguedashplayerbiostats <- function( resp <- request_with_proxy(url = full_url, ...) - df_list <- purrr::map(1:length(resp$resultSets$name), function(x){ - data <- resp$resultSets$rowSet[[x]] %>% - data.frame(stringsAsFactors = F) %>% - as_tibble() + df_list <- nba_stats_map_result_sets(resp) - json_names <- resp$resultSets$headers[[x]] - colnames(data) <- json_names - return(data) - }) - names(df_list) <- resp$resultSets$name }, error = function(e) { message(glue::glue("{Sys.time()}: Invalid arguments or no league dashboard player bio stats data for {season} available!")) @@ -284,11 +278,11 @@ nba_leaguedashplayerbiostats <- function( } #' **Get NBA Stats API League Dashboard by Player Clutch Splits** -#' @name ld_pclutch +#' @name nba_leaguedashplayerclutch NULL #' @title #' **Get NBA Stats API League Dashboard by Player Clutch Splits** -#' @rdname ld_pclutch +#' @rdname nba_leaguedashplayerclutch #' @author Saiem Gilani #' @param ahead_behind ahead_behind #' @param clutch_time clutch_time @@ -335,8 +329,13 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Players Clutch Stats](https://www.nba.com/stats/players/clutch-traditional) +#' ```r +#' nba_leaguedashplayerbiostats(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguedashplayerclutch <- function( - ahead_behind='Ahead or Behind', + ahead_behind = 'Ahead or Behind', clutch_time = 'Last 5 Minutes', college = '', conference = '', @@ -346,35 +345,35 @@ nba_leaguedashplayerclutch <- function( division = '', draft_pick = '', draft_year = '', - game_scope='', + game_scope = '', game_segment = '', height = '', - last_n_games=0, - league_id='00', - location='', - measure_type='Base', - month=0, - opponent_team_id=0, - outcome='', - pace_adjust='N', + last_n_games = 0, + league_id = '00', + location = '', + measure_type = 'Base', + month = 0, + opponent_team_id = 0, + outcome = '', + pace_adjust = 'N', plus_minus = 'N', point_diff = 5, - po_round='', - per_mode='Totals', - period=0, - player_experience='', - player_position='', + po_round = '', + per_mode = 'Totals', + period = 0, + player_experience = '', + player_position = '', rank = 'N', - season='2020-21', - season_segment='', - season_type='Regular Season', - shot_clock_range='', + season = year_to_season(most_recent_nba_season() - 1), + season_segment = '', + season_type = 'Regular Season', + shot_clock_range = '', starter_bench = '', - team_id='', + team_id = '', touch_time_range = '', - vs_conference='', - vs_division='', - weight='', + vs_conference = '', + vs_division = '', + weight = '', ...){ ahead_behind <- gsub(' ','+',ahead_behind) clutch_time <- gsub(' ','+',clutch_time) @@ -428,16 +427,8 @@ nba_leaguedashplayerclutch <- function( resp <- request_with_proxy(url = full_url, ...) - df_list <- purrr::map(1:length(resp$resultSets$name), function(x){ - data <- resp$resultSets$rowSet[[x]] %>% - data.frame(stringsAsFactors = F) %>% - as_tibble() + df_list <- nba_stats_map_result_sets(resp) - json_names <- resp$resultSets$headers[[x]] - colnames(data) <- json_names - return(data) - }) - names(df_list) <- resp$resultSets$name }, error = function(e) { message(glue::glue("{Sys.time()}: Invalid arguments or no league dashboard player clutch stats data for {season} available!")) @@ -452,11 +443,11 @@ nba_leaguedashplayerclutch <- function( #' **Get NBA Stats API League Dashboard Player Tracking - Player Shots** -#' @name ld_pptshot +#' @name nba_leaguedashplayerptshot NULL #' @title #' **Get NBA Stats API League Dashboard Player Tracking - Player Shots** -#' @rdname ld_pptshot +#' @rdname nba_leaguedashplayerptshot #' @author Saiem Gilani #' @param close_def_dist_range close_def_dist_range #' @param college college @@ -503,46 +494,51 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Players Shot Dashboard](https://www.nba.com/stats/players/shots-general) +#' ```r +#' nba_leaguedashplayerptshot(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguedashplayerptshot <- function( close_def_dist_range = '', - college='', + college = '', conference = '', country = '', date_from = '', date_to = '', - distance_range='', + distance_range = '', division = '', draft_pick = '', draft_year = '', dribble_range = '', - game_scope='', + game_scope = '', game_segment = '', - general_range='', + general_range = '', height = '', - last_n_games=0, - league_id='00', - location='', + last_n_games = 0, + league_id = '00', + location = '', measure_type = 'Base', - month=0, - opponent_team_id=0, - outcome='', + month = 0, + opponent_team_id = 0, + outcome = '', pace_adjust = 'N', - po_round='', - per_mode='Totals', - period=0, - player_experience='', - player_position='', - season='2020-21', - season_segment='', - season_type='Regular Season', - shot_clock_range='', + po_round = '', + per_mode = 'Totals', + period = 0, + player_experience = '', + player_position = '', + season = year_to_season(most_recent_nba_season() - 1), + season_segment = '', + season_type = 'Regular Season', + shot_clock_range = '', shot_dist_range = '', starter_bench = '', - team_id='', + team_id = '', touch_time_range = '', - vs_conference='', - vs_division='', - weight='', + vs_conference = '', + vs_division = '', + weight = '', ...){ season_type <- gsub(' ','+',season_type) version <- "leaguedashplayerptshot" @@ -617,11 +613,11 @@ nba_leaguedashplayerptshot <- function( #' **Get NBA Stats API League Dashboard Player Stats** -#' @name ld_pstats +#' @name nba_leaguedashplayerstats NULL #' @title #' **Get NBA Stats API League Dashboard Player Stats** -#' @rdname ld_pstats +#' @rdname nba_leaguedashplayerstats #' @author Saiem Gilani #' @param college college #' @param conference conference @@ -665,8 +661,13 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Players Stats](https://www.nba.com/stats/players/traditional) +#' ```r +#' nba_leaguedashplayerstats(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguedashplayerstats <- function( - college='', + college = '', conference = '', country = '', date_from = '', @@ -674,34 +675,34 @@ nba_leaguedashplayerstats <- function( division = '', draft_pick = '', draft_year = '', - game_scope='', + game_scope = '', game_segment = '', height = '', - last_n_games=0, - league_id='00', - location='', + last_n_games = 0, + league_id = '00', + location = '', measure_type = 'Base', - month=0, - opponent_team_id=0, - outcome='', + month = 0, + opponent_team_id = 0, + outcome = '', pace_adjust = 'N', - po_round='', - per_mode='Totals', - period=0, - player_experience='', - player_position='', - plus_minus='N', - rank='N', - season='2020-21', - season_segment='', - season_type='Regular Season', - shot_clock_range='', + po_round = '', + per_mode = 'Totals', + period = 0, + player_experience = '', + player_position = '', + plus_minus = 'N', + rank = 'N', + season = year_to_season(most_recent_nba_season() - 1), + season_segment = '', + season_type = 'Regular Season', + shot_clock_range = '', starter_bench = '', - team_id='', - two_way='', - vs_conference='', - vs_division='', - weight='', + team_id = '', + two_way = '', + vs_conference = '', + vs_division = '', + weight = '', ...){ season_type <- gsub(' ','+',season_type) version <- "leaguedashplayerstats" @@ -750,16 +751,8 @@ nba_leaguedashplayerstats <- function( resp <- request_with_proxy(url = full_url, ...) - df_list <- purrr::map(1:length(resp$resultSets$name), function(x){ - data <- resp$resultSets$rowSet[[x]] %>% - data.frame(stringsAsFactors = F) %>% - as_tibble() + df_list <- nba_stats_map_result_sets(resp) - json_names <- resp$resultSets$headers[[x]] - colnames(data) <- json_names - return(data) - }) - names(df_list) <- resp$resultSets$name }, error = function(e) { message(glue::glue("{Sys.time()}: Invalid arguments or no league dashboard player stats data for {season} available!")) @@ -773,11 +766,11 @@ nba_leaguedashplayerstats <- function( } #' **Get NBA Stats API League Dashboard Player Shot Locations** -#' @name ld_pshotloc +#' @name nba_leaguedashplayershotlocations NULL #' @title #' **Get NBA Stats API League Dashboard Player Shot Locations** -#' @rdname ld_pshotloc +#' @rdname nba_leaguedashplayershotlocations #' @author Saiem Gilani #' @param college college #' @param conference conference @@ -822,8 +815,13 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Players Shooting by Shot Location](https://www.nba.com/stats/players/shooting) +#' ```r +#' nba_leaguedashplayershotlocations(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguedashplayershotlocations <- function( - college='', + college = '', conference = '', country = '', date_from = '', @@ -836,30 +834,30 @@ nba_leaguedashplayershotlocations <- function( game_scope = '', game_segment = '', height = '', - last_n_games=0, - league_id='00', - location='', - measure_type='Base', - month=0, - opponent_team_id=0, - outcome='', - po_round='', + last_n_games = 0, + league_id = '00', + location = '', + measure_type = 'Base', + month = 0, + opponent_team_id = 0, + outcome = '', + po_round = '', pace_adjust = 'N', - per_mode='Totals', - period=0, - player_experience='', - player_position='', - plus_minus='N', + per_mode = 'Totals', + period = 0, + player_experience = '', + player_position = '', + plus_minus = 'N', rank = 'N', - season='2020-21', - season_segment='', - season_type='Regular Season', - shot_clock_range='', + season = year_to_season(most_recent_nba_season() - 1), + season_segment = '', + season_type = 'Regular Season', + shot_clock_range = '', starter_bench = '', - team_id='', - vs_conference='', - vs_division='', - weight='', + team_id = '', + vs_conference = '', + vs_division = '', + weight = '', ...){ distance_range <- gsub(' ','+',distance_range) @@ -914,13 +912,13 @@ nba_leaguedashplayershotlocations <- function( df_list <- purrr::map(1:length(resp$resultSets$name), function(x){ data <- resp$resultSets$rowSet %>% data.frame(stringsAsFactors = F) %>% - as_tibble() + dplyr::as_tibble() columnsToSkip <- resp$resultSets$headers$columnsToSkip[[1]] columnSpan <- resp$resultSets$headers$columnSpan[[1]] json_names1 <- resp$resultSets$headers$columnNames[[1]] - json_names_rep <- rep(json_names1,times=1,each=columnSpan) + json_names_rep <- rep(json_names1, times = 1, each = columnSpan) json_names2 <- resp$resultSets$headers$columnNames[[2]] - json_names <- c(json_names2[1:columnsToSkip], paste(json_names_rep, json_names2[(columnsToSkip+1):30])) + json_names <- c(json_names2[1:columnsToSkip], paste(json_names_rep, json_names2[(columnsToSkip + 1):30])) colnames(data) <- gsub('\\(|\\)|','', gsub(' |-','_',json_names)) return(data) }) @@ -939,11 +937,11 @@ nba_leaguedashplayershotlocations <- function( #' **Get NBA Stats API League Dashboard Player Tracking - Defense** -#' @name ld_ptdefend +#' @name nba_leaguedashptdefend NULL #' @title #' **Get NBA Stats API League Dashboard Player Tracking - Defense** -#' @rdname ld_ptdefend +#' @rdname nba_leaguedashptdefend #' @author Saiem Gilani #' @param college college #' @param conference conference @@ -982,6 +980,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Defensive Dashboard](https://www.nba.com/stats/players/defense-dash-overall) +#' ```r +#' nba_leaguedashptdefend(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguedashptdefend <- function( college = '', conference = '', @@ -994,26 +997,26 @@ nba_leaguedashptdefend <- function( draft_year = '', game_segment = '', height = '', - last_n_games=0, - league_id='00', - location='', - month=0, - opponent_team_id=0, - outcome='', - po_round='', - per_mode='Totals', - period='', - player_experience='', - player_id='', - player_position='', - season='2020-21', - season_segment='', - season_type='Regular Season', + last_n_games = 0, + league_id = '00', + location = '', + month = 0, + opponent_team_id = 0, + outcome = '', + po_round = '', + per_mode = 'Totals', + period = '', + player_experience = '', + player_id = '', + player_position = '', + season = year_to_season(most_recent_nba_season() - 1), + season_segment = '', + season_type = 'Regular Season', starter_bench = '', - team_id='', - vs_conference='', - vs_division='', - weight='', + team_id = '', + vs_conference = '', + vs_division = '', + weight = '', ...){ season_type <- gsub(' ','+',season_type) version <- "leaguedashptdefend" @@ -1057,16 +1060,8 @@ nba_leaguedashptdefend <- function( resp <- request_with_proxy(url = full_url, ...) - df_list <- purrr::map(1:length(resp$resultSets$name), function(x){ - data <- resp$resultSets$rowSet[[x]] %>% - data.frame(stringsAsFactors = F) %>% - as_tibble() + df_list <- nba_stats_map_result_sets(resp) - json_names <- resp$resultSets$headers[[x]] - colnames(data) <- json_names - return(data) - }) - names(df_list) <- resp$resultSets$name }, error = function(e) { message(glue::glue("{Sys.time()}: Invalid arguments or no league dashboard player-tracking player defense data for {season} available!")) @@ -1081,11 +1076,11 @@ nba_leaguedashptdefend <- function( #' **Get NBA Stats API League Dashboard Player Tracking - Stats** -#' @name ld_ptstats +#' @name nba_leaguedashptstats NULL #' @title #' **Get NBA Stats API League Dashboard Player Tracking - Stats** -#' @rdname ld_ptstats +#' @rdname nba_leaguedashptstats #' @author Saiem Gilani #' @param college college #' @param conference conference @@ -1123,6 +1118,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Players Tracking (Second Spectrum) Stats](https://www.nba.com/stats/players/drives) +#' ```r +#' nba_leaguedashptstats(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguedashptstats <- function( college = '', conference = '', @@ -1134,27 +1134,27 @@ nba_leaguedashptstats <- function( draft_year = '', game_scope = '', height = '', - last_n_games=0, - league_id='00', - location='', - month=0, - opponent_team_id=0, - outcome='', - po_round='', - per_mode='Totals', - period='', - player_experience='', - player_or_team='Team', - player_position='', - pt_measure_type = 'SpeedDistance', - season='2020-21', - season_segment='', - season_type='Regular Season', + last_n_games = 0, + league_id = '00', + location = '', + month = 0, + opponent_team_id = 0, + outcome = '', + po_round = '', + per_mode = 'PerGame', + period = '', + player_experience = '', + player_or_team = 'Player', + player_position = '', + pt_measure_type = 'Drives', + season = year_to_season(most_recent_nba_season() - 1), + season_segment = '', + season_type = 'Regular Season', starter_bench = '', - team_id='', - vs_conference='', - vs_division='', - weight='', + team_id = '', + vs_conference = '', + vs_division = '', + weight = '', ...){ season_type <- gsub(' ','+',season_type) version <- "leaguedashptstats" @@ -1198,16 +1198,8 @@ nba_leaguedashptstats <- function( resp <- request_with_proxy(url = full_url, ...) - df_list <- purrr::map(1:length(resp$resultSets$name), function(x){ - data <- resp$resultSets$rowSet[[x]] %>% - data.frame(stringsAsFactors = F) %>% - as_tibble() + df_list <- nba_stats_map_result_sets(resp) - json_names <- resp$resultSets$headers[[x]] - colnames(data) <- json_names - return(data) - }) - names(df_list) <- resp$resultSets$name }, error = function(e) { message(glue::glue("{Sys.time()}: Invalid arguments or no league dashboard player-tracking stats data for {season} available!")) @@ -1222,11 +1214,11 @@ nba_leaguedashptstats <- function( #' **Get NBA Stats API League Dashboard Player Tracking - Team Defense** -#' @name ld_ptteamdefend +#' @name nba_leaguedashptteamdefend NULL #' @title #' **Get NBA Stats API League Dashboard Player Tracking - Team Defense** -#' @rdname ld_ptteamdefend +#' @rdname nba_leaguedashptteamdefend #' @author Saiem Gilani #' @param conference conference #' @param date_from date_from @@ -1254,6 +1246,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Defensive Dashboard](https://www.nba.com/stats/teams/defense-dash-overall) +#' ```r +#' nba_leaguedashptteamdefend(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguedashptteamdefend <- function( conference = '', date_from = '', @@ -1261,21 +1258,21 @@ nba_leaguedashptteamdefend <- function( defense_category = 'Overall', division = '', game_segment = '', - last_n_games=0, - league_id='00', - location='', - month=0, - opponent_team_id=0, - outcome='', - po_round='', - per_mode='Totals', - period='', - season='2020-21', - season_segment='', - season_type='Regular Season', - team_id='', - vs_conference='', - vs_division='', + last_n_games = 0, + league_id = '00', + location = '', + month = 0, + opponent_team_id = 0, + outcome = '', + po_round = '', + per_mode = 'PerGame', + period = '', + season = year_to_season(most_recent_nba_season() - 1), + season_segment = '', + season_type = 'Regular Season', + team_id = '', + vs_conference = '', + vs_division = '', ...){ season_type <- gsub(' ','+',season_type) version <- "leaguedashptteamdefend" @@ -1309,16 +1306,8 @@ nba_leaguedashptteamdefend <- function( resp <- request_with_proxy(url = full_url, ...) - df_list <- purrr::map(1:length(resp$resultSets$name), function(x){ - data <- resp$resultSets$rowSet[[x]] %>% - data.frame(stringsAsFactors = F) %>% - as_tibble() + df_list <- nba_stats_map_result_sets(resp) - json_names <- resp$resultSets$headers[[x]] - colnames(data) <- json_names - return(data) - }) - names(df_list) <- resp$resultSets$name }, error = function(e) { message(glue::glue("{Sys.time()}: Invalid arguments or no league dashboard player-tracking team defensive stats data for {season} available!")) @@ -1333,11 +1322,11 @@ nba_leaguedashptteamdefend <- function( #' **Get NBA Stats API League Dashboard by Team Clutch Splits** -#' @name ld_tclutch +#' @name nba_leaguedashteamclutch NULL #' @title #' **Get NBA Stats API League Dashboard by Team Clutch Splits** -#' @rdname ld_tclutch +#' @rdname nba_leaguedashteamclutch #' @author Saiem Gilani #' @param ahead_behind ahead_behind #' @param clutch_time clutch_time @@ -1377,43 +1366,48 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Clutch Stats](https://www.nba.com/stats/teams/clutch-traditional) +#' ```r +#' nba_leaguedashteamclutch(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguedashteamclutch <- function( - ahead_behind='Ahead or Behind', + ahead_behind = 'Ahead or Behind', clutch_time = 'Last 5 Minutes', conference = '', date_from = '', date_to = '', division = '', - game_scope='', + game_scope = '', game_segment = '', - last_n_games=0, - league_id='00', - location='', - measure_type='Base', - month=0, - opponent_team_id=0, - outcome='', + last_n_games = 0, + league_id = '00', + location = '', + measure_type = 'Base', + month = 0, + opponent_team_id = 0, + outcome = '', pace_adjust='N', plus_minus = 'N', point_diff = 5, - po_round='', - per_mode='Totals', - period=0, - player_experience='', - player_position='', + po_round = '', + per_mode = 'Totals', + period = 0, + player_experience = '', + player_position = '', rank = 'N', - season='2020-21', - season_segment='', - season_type='Regular Season', - shot_clock_range='', + season = year_to_season(most_recent_nba_season() - 1), + season_segment = '', + season_type = 'Regular Season', + shot_clock_range = '', starter_bench = '', - team_id='', - vs_conference='', - vs_division='', + team_id = '', + vs_conference = '', + vs_division = '', ...){ - ahead_behind <- gsub(' ','+',ahead_behind) - clutch_time <- gsub(' ','+',clutch_time) - season_type <- gsub(' ','+',season_type) + ahead_behind <- gsub(' ', '+', ahead_behind) + clutch_time <- gsub(' ', '+', clutch_time) + season_type <- gsub(' ', '+', season_type) version <- "leaguedashteamclutch" endpoint <- nba_endpoint(version) @@ -1456,16 +1450,8 @@ nba_leaguedashteamclutch <- function( resp <- request_with_proxy(url = full_url, ...) - df_list <- purrr::map(1:length(resp$resultSets$name), function(x){ - data <- resp$resultSets$rowSet[[x]] %>% - data.frame(stringsAsFactors = F) %>% - as_tibble() + df_list <- nba_stats_map_result_sets(resp) - json_names <- resp$resultSets$headers[[x]] - colnames(data) <- json_names - return(data) - }) - names(df_list) <- resp$resultSets$name }, error = function(e) { message(glue::glue("{Sys.time()}: Invalid arguments or no league dashboard team clutch data for {season} available!")) @@ -1480,11 +1466,11 @@ nba_leaguedashteamclutch <- function( #' **Get NBA Stats API League Dashboard Player Tracking - Team Shots** -#' @name ld_tptshot +#' @name nba_leaguedashteamptshot NULL #' @title #' **Get NBA Stats API League Dashboard Player Tracking - Team Shots** -#' @rdname ld_tptshot +#' @rdname nba_leaguedashteamptshot #' @author Saiem Gilani #' @param close_def_dist_range close_def_dist_range #' @param conference conference @@ -1518,6 +1504,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Shot Dashboard](https://www.nba.com/stats/teams/shots-general) +#' ```r +#' nba_leaguedashteamptshot(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguedashteamptshot <- function( close_def_dist_range = '', conference = '', @@ -1526,25 +1517,25 @@ nba_leaguedashteamptshot <- function( division = '', dribble_range = '', game_segment = '', - general_range='', - last_n_games=0, - league_id='00', - location='', - month=0, - opponent_team_id=0, - outcome='', - po_round='', - per_mode='Totals', - period=0, - season='2020-21', - season_segment='', - season_type='Regular Season', - shot_clock_range='', + general_range = '', + last_n_games = 0, + league_id = '00', + location = '', + month = 0, + opponent_team_id = 0, + outcome = '', + po_round = '', + per_mode = 'Totals', + period = 0, + season = year_to_season(most_recent_nba_season() - 1), + season_segment = '', + season_type = 'Regular Season', + shot_clock_range = '', shot_dist_range = '', - team_id='', + team_id = '', touch_time_range = '', - vs_conference='', - vs_division='', + vs_conference = '', + vs_division = '', ...){ season_type <- gsub(' ','+',season_type) version <- "leaguedashteamptshot" @@ -1582,16 +1573,8 @@ nba_leaguedashteamptshot <- function( resp <- request_with_proxy(url = full_url, ...) - df_list <- purrr::map(1:length(resp$resultSets$name), function(x){ - data <- resp$resultSets$rowSet[[x]] %>% - data.frame(stringsAsFactors = F) %>% - as_tibble() + df_list <- nba_stats_map_result_sets(resp) - json_names <- resp$resultSets$headers[[x]] - colnames(data) <- json_names - return(data) - }) - names(df_list) <- resp$resultSets$name }, error = function(e) { message(glue::glue("{Sys.time()}: Invalid arguments or no league dashboard team player-tracking shooting stats data for {season} available!")) @@ -1606,11 +1589,11 @@ nba_leaguedashteamptshot <- function( #' **Get NBA Stats API League Dashboard Team Stats** -#' @name ld_tstats +#' @name nba_leaguedashteamstats NULL #' @title #' **Get NBA Stats API League Dashboard Team Stats** -#' @rdname ld_tstats +#' @rdname nba_leaguedashteamstats #' @author Saiem Gilani #' @param conference conference #' @param date_from date_from @@ -1646,35 +1629,40 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Stats](https://www.nba.com/stats/teams/traditional) +#' ```r +#' nba_leaguedashteamstats(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguedashteamstats <- function( conference = '', date_from = '', date_to = '', division = '', - game_scope='', + game_scope = '', game_segment = '', - last_n_games=0, - league_id='00', - location='', - measure_type='Base', - month=0, - opponent_team_id=0, - outcome='', - po_round='', - pace_adjust='N', - per_mode='Totals', - period=0, - plus_minus='N', - rank='N', - season='2020-21', - season_segment='', - season_type='Regular Season', - shot_clock_range='', - starter_bench='', - team_id='', - two_way='', - vs_conference='', - vs_division='', + last_n_games = 0, + league_id = '00', + location = '', + measure_type = 'Base', + month = 0, + opponent_team_id = 0, + outcome = '', + po_round = '', + pace_adjust = 'N', + per_mode = 'Totals', + period = 0, + plus_minus = 'N', + rank = 'N', + season = year_to_season(most_recent_nba_season() - 1), + season_segment = '', + season_type = 'Regular Season', + shot_clock_range = '', + starter_bench = '', + team_id = '', + two_way = '', + vs_conference = '', + vs_division = '', ...){ season_type <- gsub(' ','+',season_type) version <- "leaguedashteamstats" @@ -1715,16 +1703,8 @@ nba_leaguedashteamstats <- function( resp <- request_with_proxy(url = full_url, ...) - df_list <- purrr::map(1:length(resp$resultSets$name), function(x){ - data <- resp$resultSets$rowSet[[x]] %>% - data.frame(stringsAsFactors = F) %>% - as_tibble() + df_list <- nba_stats_map_result_sets(resp) - json_names <- resp$resultSets$headers[[x]] - colnames(data) <- json_names - return(data) - }) - names(df_list) <- resp$resultSets$name }, error = function(e) { message(glue::glue("{Sys.time()}: Invalid arguments or no league dashboard team stats data for {season} available!")) @@ -1739,11 +1719,11 @@ nba_leaguedashteamstats <- function( #' **Get NBA Stats API League Dashboard Team Shot Locations** -#' @name ld_tshotloc +#' @name nba_leaguedashteamshotlocations NULL #' @title #' **Get NBA Stats API League Dashboard Team Shot Locations** -#' @rdname ld_tshotloc +#' @rdname nba_leaguedashteamshotlocations #' @author Saiem Gilani #' @param conference conference #' @param date_from date_from @@ -1781,6 +1761,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Shooting by Shot Location](https://www.nba.com/stats/teams/shooting) +#' ```r +#' nba_leaguedashteamshotlocations(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguedashteamshotlocations <- function( conference = '', date_from = '', @@ -1789,29 +1774,29 @@ nba_leaguedashteamshotlocations <- function( division = '', game_scope = '', game_segment = '', - last_n_games=0, - league_id='00', - location='', - measure_type='Base', - month=0, - opponent_team_id=0, - outcome='', - po_round='', + last_n_games = 0, + league_id = '00', + location = '', + measure_type = 'Base', + month = 0, + opponent_team_id = 0, + outcome = '', + po_round = '', pace_adjust = 'N', - per_mode='Totals', - period=0, - player_experience='', - player_position='', - plus_minus='N', + per_mode = 'Totals', + period = 0, + player_experience = '', + player_position = '', + plus_minus = 'N', rank = 'N', - season='2020-21', - season_segment='', - season_type='Regular Season', - shot_clock_range='', + season = year_to_season(most_recent_nba_season() - 1), + season_segment = '', + season_type = 'Regular Season', + shot_clock_range = '', starter_bench = '', - team_id='', - vs_conference='', - vs_division='', + team_id = '', + vs_conference = '', + vs_division = '', ...){ distance_range <- gsub(' ','+',distance_range) @@ -1859,13 +1844,13 @@ nba_leaguedashteamshotlocations <- function( df_list <- purrr::map(1:length(resp$resultSets$name), function(x){ data <- resp$resultSets$rowSet %>% data.frame(stringsAsFactors = F) %>% - as_tibble() + dplyr::as_tibble() columnsToSkip <- resp$resultSets$headers$columnsToSkip[[1]] columnSpan <- resp$resultSets$headers$columnSpan[[1]] json_names1 <- resp$resultSets$headers$columnNames[[1]] - json_names_rep <- rep(json_names1,times=1,each=columnSpan) + json_names_rep <- rep(json_names1,times = 1, each = columnSpan) json_names2 <- resp$resultSets$headers$columnNames[[2]] - json_names <- c(json_names2[1:columnsToSkip], paste(json_names_rep, json_names2[(columnsToSkip+1):30])) + json_names <- c(json_names2[1:columnsToSkip], paste(json_names_rep, json_names2[(columnsToSkip + 1):30])) colnames(data) <- gsub('\\(|\\)|','', gsub(' |-','_',json_names)) return(data) }) diff --git a/R/nba_stats_lineups.R b/R/nba_stats_lineups.R index 9b81ef58..cea40b0f 100644 --- a/R/nba_stats_lineups.R +++ b/R/nba_stats_lineups.R @@ -1,9 +1,9 @@ #' **Get NBA Stats API Fantasy Widget** -#' @name fantasywidget +#' @name nba_fantasywidget NULL #' @title #' **Get NBA Stats API Fantasy Widget** -#' @rdname fantasywidget +#' @rdname nba_fantasywidget #' @author Saiem Gilani #' @param active_players active_players #' @param date_from date_from date_from @@ -30,6 +30,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_fantasywidget(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_fantasywidget <- function( active_players = 'N', date_from = '', @@ -42,7 +46,7 @@ nba_fantasywidget <- function( po_round = '', player_id = '', position = '', - season = '2019-20', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '', @@ -95,11 +99,11 @@ nba_fantasywidget <- function( } #' **Get NBA Stats API League Dashboard Lineups** -#' @name leaguedashlineups +#' @name nba_leaguedashlineups NULL #' @title #' **Get NBA Stats API League Dashboard Lineups** -#' @rdname leaguedashlineups +#' @rdname nba_leaguedashlineups #' @author Saiem Gilani #' @param conference conference #' @param date_from date_from @@ -133,6 +137,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Lineups Dashboard](https://www.nba.com/stats/lineups/traditional) +#' ```r +#' nba_leaguedashlineups(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguedashlineups <- function( conference = '', date_from = '', @@ -153,7 +162,7 @@ nba_leaguedashlineups <- function( period = 0, plus_minus = 'N', rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -212,11 +221,11 @@ nba_leaguedashlineups <- function( } #' **Get NBA Stats API League Lineup Visual Data** -#' @name leaguelineupviz +#' @name nba_leaguelineupviz NULL #' @title #' **Get NBA Stats API League Lineup Visual Data** -#' @rdname leaguelineupviz +#' @rdname nba_leaguelineupviz #' @author Saiem Gilani #' @param conference conference #' @param date_from date_from @@ -251,6 +260,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Lineups Dashboard](https://www.nba.com/stats/lineups/traditional) +#' ```r +#' nba_leaguelineupviz(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leaguelineupviz <- function( conference = '', date_from = '', @@ -272,7 +286,7 @@ nba_leaguelineupviz <- function( period = 0, plus_minus = 'N', rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -334,11 +348,11 @@ nba_leaguelineupviz <- function( #' **Get NBA Stats API League Player On/Off Details** -#' @name leagueplayerondetails +#' @name nba_leagueplayerondetails NULL #' @title #' **Get NBA Stats API League Player On/Off Details** -#' @rdname leagueplayerondetails +#' @rdname nba_leagueplayerondetails #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -367,6 +381,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_leagueplayerondetails(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leagueplayerondetails <- function( date_from = '', date_to = '', @@ -383,7 +401,7 @@ nba_leagueplayerondetails <- function( period = 0, plus_minus = 'N', rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '1610612749', @@ -439,11 +457,11 @@ nba_leagueplayerondetails <- function( #' **Get NBA Stats API League Season Matchups** -#' @name leagueseasonmatchups +#' @name nba_leagueseasonmatchups NULL #' @title #' **Get NBA Stats API League Season Matchups** -#' @rdname leagueseasonmatchups +#' @rdname nba_leagueseasonmatchups #' @author Saiem Gilani #' @param def_player_id def_player_id #' @param def_team_id def_team_id @@ -459,6 +477,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Season Matchups](https://www.nba.com/stats/player/2544/head-to-head) +#' ```r +#' nba_leagueseasonmatchups(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_leagueseasonmatchups <- function( def_player_id = '', def_team_id = '', @@ -466,7 +489,7 @@ nba_leagueseasonmatchups <- function( off_player_id = '', off_team_id = '', per_mode = 'Totals', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', ...){ season_type <- gsub(' ','+',season_type) @@ -501,11 +524,11 @@ nba_leagueseasonmatchups <- function( return(df_list) } #' **Get NBA Stats API Matchups Rollup** -#' @name matchupsrollup +#' @name nba_matchupsrollup NULL #' @title #' **Get NBA Stats API Matchups Rollup** -#' @rdname matchupsrollup +#' @rdname nba_matchupsrollup #' @author Saiem Gilani #' @param def_player_id def_player_id #' @param def_team_id def_team_id @@ -521,6 +544,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Matchups Rollup](https://www.nba.com/stats/player/2544/by-position) +#' ```r +#' nba_matchupsrollup(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_matchupsrollup <- function( def_player_id = '', def_team_id = '', @@ -528,7 +556,7 @@ nba_matchupsrollup <- function( off_player_id = '', off_team_id = '', per_mode = 'Totals', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', ...){ season_type <- gsub(' ','+',season_type) diff --git a/R/nba_stats_pbp.R b/R/nba_stats_pbp.R index 89f9579c..98cc1435 100644 --- a/R/nba_stats_pbp.R +++ b/R/nba_stats_pbp.R @@ -1,10 +1,10 @@ #' **Get NBA Stats API play-by-play** -#' @name pbp +#' @name nba_pbp NULL #' @title #' **Get NBA Stats API play-by-play** -#' @rdname pbp +#' @rdname nba_pbp #' @author Jason Lee #' @param game_id Game ID #' @param version Play-by-play version ("v2" available from 2016-17 onwards) @@ -15,6 +15,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_pbp(game_id = 0022201086) +#' ``` nba_pbp <- function( game_id, version = "v2", @@ -60,7 +64,7 @@ nba_pbp <- function( "wc_time_string" = "wctimestring", "time_quarter" = "pctimestring", "score_margin" = "scoremargin", - "even_num" = "eventnum", + "event_num" = "eventnum", "event_msg_type" = "eventmsgtype", "event_msg_action_type" = "eventmsgactiontype", "home_description" = "homedescription", @@ -125,11 +129,11 @@ nba_pbp <- function( #' **Get NBA Stats API play-by-play (Multiple Games)** -#' @name pbps +#' @name nba_pbps NULL #' @title #' **Get NBA Stats API play-by-play (Multiple Games)** -#' @rdname pbps +#' @rdname nba_pbps #' @author Jason Lee #' @param game_ids Game IDs #' @param version Play-by-play version ("v2" available from 2016-17 onwards) @@ -171,123 +175,115 @@ nba_pbps <- function( -#' **Get NBA Stats API Season Schedule** -#' @name nba_stats_schedule + +#' **Get NBA Stats API Live play-by-play** +#' @name nba_live_pbp NULL #' @title -#' **Get NBA Stats API Season Schedule** -#' @rdname nba_stats_schedule +#' **Get NBA Stats API Live play-by-play** +#' @rdname nba_live_pbp #' @author Saiem Gilani -#' @param league_id League - default: '00'. Other options include '10': WNBA, '20': G-League -#' @param season Season +#' @param game_id Game ID #' @param ... Additional arguments passed to an underlying function like httr. +#' @return Returns a data frame: PlayByPlay #' @importFrom jsonlite fromJSON toJSON #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest -#' @return Returns a tibble with the following columns: -#' -#' |col_name |types | -#' |:------------------|:---------| -#' |game_date |character | -#' |game_id |character | -#' |game_code |character | -#' |game_status |integer | -#' |game_status_text |character | -#' |game_sequence |integer | -#' |game_date_est |character | -#' |game_time_est |character | -#' |game_date_time_est |character | -#' |game_date_utc |character | -#' |game_time_utc |character | -#' |game_date_time_utc |character | -#' |away_team_time |character | -#' |home_team_time |character | -#' |day |character | -#' |month_num |integer | -#' |week_number |integer | -#' |week_name |character | -#' |if_necessary |character | -#' |series_game_number |character | -#' |series_text |character | -#' |arena_name |character | -#' |arena_state |character | -#' |arena_city |character | -#' |postponed_status |character | -#' |branch_link |character | -#' |game_subtype |character | -#' |home_team_id |integer | -#' |home_team_name |character | -#' |home_team_city |character | -#' |home_team_tricode |character | -#' |home_team_slug |character | -#' |home_team_wins |integer | -#' |home_team_losses |integer | -#' |home_team_score |integer | -#' |home_team_seed |integer | -#' |away_team_id |integer | -#' |away_team_name |character | -#' |away_team_city |character | -#' |away_team_tricode |character | -#' |away_team_slug |character | -#' |away_team_wins |integer | -#' |away_team_losses |integer | -#' |away_team_score |integer | -#' |away_team_seed |integer | -#' |season |character | -#' |league_id |character | -#' #' @export -nba_schedule <- function( - league_id = '00', - season = year_to_season(most_recent_nba_season() - 1), +#' @details +#' ```r +#' nba_live_pbp(game_id = 0022201086) +#' ``` +nba_live_pbp <- function( + game_id, ...){ - version <- "scheduleleaguev2" - full_url <- nba_endpoint(version) - params <- list( - LeagueID = league_id, - Season = season - ) + endpoint <- nba_live_endpoint('playbyplay') + + full_url <- paste0(endpoint, + "/playbyplay_", + pad_id(game_id), + ".json") + tryCatch( expr = { - resp <- request_with_proxy(url = full_url, params, ...) + res <- rvest::session(url = full_url, ..., httr::timeout(60)) + + resp <- res$response %>% + httr::content(as = "text", encoding = "UTF-8") %>% + jsonlite::fromJSON() - league_sched <- resp %>% - purrr::pluck("leagueSchedule") - games <- league_sched %>% - purrr::pluck("gameDates") %>% - tidyr::unnest("games") %>% - tidyr::unnest("awayTeam", names_sep = "_") %>% - tidyr::unnest("homeTeam", names_sep = "_") %>% - dplyr::select(-dplyr::any_of(c("broadcasters", "pointsLeaders"))) %>% + data <- resp %>% + purrr::pluck("game") %>% + purrr::pluck("actions") %>% janitor::clean_names() - colnames(games) <- gsub('team_team', 'team', colnames(games)) - games$game_id <- unlist(purrr::map(games$game_id,function(x){ - pad_id(x) - })) - games$season <- league_sched$seasonYear - games$league_id <- league_sched$leagueId - games <- games %>% - dplyr::mutate( - season_type_id = substr(.data$game_id, 3, 3), - season_type_description = dplyr::case_when( - .data$season_type_id == 1 ~ "Pre-Season", - .data$season_type_id == 2 ~ "Regular Season", - .data$season_type_id == 3 ~ "All-Star", - .data$season_type_id == 4 ~ "Playoffs", - .data$season_type_id == 5 ~ "Play-In Game"), - game_date = lubridate::ymd(substring(.data$game_date,1,10))) }, error = function(e) { - message(glue::glue("{Sys.time()}: Invalid arguments or no league schedule data for {season} available!")) + message(glue::glue("{Sys.time()}: Invalid arguments or no play-by-play data for {game_id} available!")) + }, + warning = function(w) { + }, + finally = { + } + ) + return(data) +} + + + +#' **Get NBA Stats API Live Boxscore** +#' @name nba_live_boxscore +NULL +#' @title +#' **Get NBA Stats API Live Boxscore** +#' @rdname nba_live_boxscore +#' @author Saiem Gilani +#' @param game_id Game ID +#' @param ... Additional arguments passed to an underlying function like httr. +#' @return Returns a data frame: PlayByPlay +#' @importFrom jsonlite fromJSON toJSON +#' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble +#' @import rvest +#' @export +#' @details +#' ```r +#' nba_live_boxscore(game_id = 0022201086) +#' ``` +nba_live_boxscore <- function( + game_id, + ...){ + + + endpoint <- nba_live_endpoint('boxscore') + + full_url <- paste0(endpoint, + "/boxscore_", + pad_id(game_id), + ".json") + + tryCatch( + expr = { + + res <- rvest::session(url = full_url, httr::timeout(60)) + + resp <- res$response %>% + httr::content(as = "text", encoding = "UTF-8") %>% + jsonlite::fromJSON() + + data <- resp %>% + purrr::pluck("game") + + }, + error = function(e) { + message(glue::glue("{Sys.time()}: Invalid arguments or no play-by-play data for {game_id} available!")) }, warning = function(w) { }, finally = { } ) - return(games) + return(data) } diff --git a/R/nba_stats_player.R b/R/nba_stats_player.R index 440d3217..757b7c38 100644 --- a/R/nba_stats_player.R +++ b/R/nba_stats_player.R @@ -1,10 +1,10 @@ #' **Get NBA Stats API Player Index** -#' @name p_index +#' @name nba_playerindex NULL #' @title #' **Get NBA Stats API Player Index** -#' @rdname p_index +#' @rdname nba_playerindex #' @author Saiem Gilani #' @param college Player College #' @param country Player Country @@ -24,6 +24,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Index](https://www.nba.com/stats/players) +#' ```r +#' nba_playerindex() +#' ``` nba_playerindex <- function( college = '', country = '', @@ -33,7 +38,7 @@ nba_playerindex <- function( height = '', historical = 1, league_id = '00', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', team_id = '0', weight = '', @@ -77,11 +82,11 @@ nba_playerindex <- function( } #' **Get NBA Stats API Player Head-shot** -#' @name p_headshot +#' @name nba_playerheadshot NULL #' @title #' **Get NBA Stats API Player Head-shot** -#' @rdname p_headshot +#' @rdname nba_playerheadshot #' @author Saiem Gilani #' @param player_id Player ID #' @param ... Additional arguments passed to an underlying function like httr. @@ -90,6 +95,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Headshot](https://cdn.nba.com/headshots/nba/latest/260x190/2544.png) +#' ```r +#' nba_playerheadshot(player_id = '2544') +#' ``` nba_playerheadshot <- function( player_id = '2544', ...){ @@ -115,11 +125,11 @@ nba_playerheadshot <- function( } #' **Get NBA Stats API Player Awards** -#' @name playerawards +#' @name nba_playerawards NULL #' @title #' **Get NBA Stats API Player Awards** -#' @rdname playerawards +#' @rdname nba_playerawards #' @author Saiem Gilani #' @param player_id Player ID #' @param ... Additional arguments passed to an underlying function like httr. @@ -128,6 +138,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Awards](https://www.nba.com/stats/player/2544/career) +#' ```r +#' nba_playerawards(player_id = '2544') +#' ``` nba_playerawards <- function( player_id, ...){ @@ -157,11 +172,11 @@ nba_playerawards <- function( } #' **Get NBA Stats API Player Career By College** -#' @name pcareerbycollege +#' @name nba_playercareerbycollege NULL #' @title #' **Get NBA Stats API Player Career By College** -#' @rdname pcareerbycollege +#' @rdname nba_playercareerbycollege #' @author Saiem Gilani #' @param college College Name #' @param season Season - format 2020-21 @@ -174,11 +189,15 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_playercareerbycollege(college = 'Florida State', per_mode = 'PerGame') +#' ``` nba_playercareerbycollege <- function( college = 'Florida State', league_id = '00', per_mode = 'Totals', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', ...){ college <- gsub(' ','+',college) @@ -213,11 +232,11 @@ nba_playercareerbycollege <- function( #' **Get NBA Stats API Player Career By College Rollup** -#' @name pcareerbycollege_ru +#' @name nba_playercareerbycollegerollup NULL #' @title #' **Get NBA Stats API Player Career By College Rollup** -#' @rdname pcareerbycollege_ru +#' @rdname nba_playercareerbycollegerollup #' @author Saiem Gilani #' @param season Season - format 2020-21 #' @param season_type Season Type - Regular Season, Playoffs, All-Star @@ -229,10 +248,14 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_playercareerbycollegerollup(per_mode = 'Totals') +#' ``` nba_playercareerbycollegerollup <- function( league_id = '00', per_mode = 'Totals', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', ...){ @@ -248,7 +271,7 @@ nba_playercareerbycollegerollup <- function( tryCatch( expr = { - resp <- request_with_proxy(url = full_url, ...) + resp <- request_with_proxy(url = full_url) df_list <- nba_stats_map_result_sets(resp) @@ -266,11 +289,11 @@ nba_playercareerbycollegerollup <- function( #' **Get NBA Stats API Player Career Stats** -#' @name playercareerstats +#' @name nba_playercareerstats NULL #' @title #' **Get NBA Stats API Player Career Stats** -#' @rdname playercareerstats +#' @rdname nba_playercareerstats #' @author Saiem Gilani #' @param player_id Player ID #' @param per_mode Per Mode - PerGame, Totals @@ -283,6 +306,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Career Stats](https://www.nba.com/stats/player/2544/career) +#' ```r +#' nba_playercareerstats(player_id = '2544') +#' ``` nba_playercareerstats <- function( league_id = '00', per_mode = 'Totals', @@ -317,11 +345,11 @@ nba_playercareerstats <- function( } #' **Get NBA Stats API Player Fantasy Profile** -#' @name pfantasy +#' @name nba_playerfantasyprofile NULL #' @title #' **Get NBA Stats API Player Fantasy Profile** -#' @rdname pfantasy +#' @rdname nba_playerfantasyprofile #' @author Saiem Gilani #' @param league_id League - default: '00'. Other options include '10': WNBA, '20': G-League #' @param measure_type measure_type @@ -338,6 +366,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_playerfantasyprofile(player_id = '2544') +#' ``` nba_playerfantasyprofile <- function( league_id = '00', measure_type = 'Base', @@ -346,7 +378,7 @@ nba_playerfantasyprofile <- function( player_id = '2544', plus_minus = 'N', rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', ...){ @@ -387,11 +419,11 @@ nba_playerfantasyprofile <- function( #' **Get NBA Stats API Player Fantasy Profile Bar Graph** -#' @name pfantasy_bg +#' @name nba_playerfantasyprofilebargraph NULL #' @title #' **Get NBA Stats API Player Fantasy Profile Bar Graph** -#' @rdname pfantasy_bg +#' @rdname nba_playerfantasyprofilebargraph #' @author Saiem Gilani #' @param league_id League - default: '00'. Other options include '10': WNBA, '20': G-League #' @param player_id Player ID @@ -403,10 +435,14 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_playerfantasyprofilebargraph(player_id = '2544') +#' ``` nba_playerfantasyprofilebargraph <- function( league_id = '00', player_id = '2544', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', ...){ @@ -441,11 +477,11 @@ nba_playerfantasyprofilebargraph <- function( #' **Get NBA Stats API Player Estimated Metrics** -#' @name p_est_metr +#' @name nba_playerestimatedmetrics NULL #' @title #' **Get NBA Stats API Player Estimated Metrics** -#' @rdname p_est_metr +#' @rdname nba_playerestimatedmetrics #' @author Saiem Gilani #' @param season Season - format 2020-21 #' @param season_type Season Type - Regular Season, Playoffs, All-Star @@ -456,9 +492,14 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Estimated Metrics](https://www.nba.com/stats/players/estimated-advanced) +#' ```r +#' nba_playerestimatedmetrics() +#' ``` nba_playerestimatedmetrics <- function( league_id = '00', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', ...){ @@ -474,9 +515,19 @@ nba_playerestimatedmetrics <- function( tryCatch( expr = { - resp <- request_with_proxy(url = full_url, ...) + resp <- request_with_proxy(url = full_url) - df_list <- nba_stats_map_result_sets(resp) + + df_list <- purrr::map(1:length(resp$resultSet$name), function(x){ + data <- resp$resultSet$rowSet %>% + data.frame(stringsAsFactors = F) %>% + dplyr::as_tibble() + + json_names <- resp$resultSet$headers + colnames(data) <- json_names + return(data) + }) + names(df_list) <- resp$resultSet$name }, error = function(e) { @@ -492,11 +543,11 @@ nba_playerestimatedmetrics <- function( #' **Get NBA Stats API Player Game Log** -#' @name p_gamelog +#' @name nba_playergamelog NULL #' @title #' **Get NBA Stats API Player Game Log** -#' @rdname p_gamelog +#' @rdname nba_playergamelog #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -510,12 +561,17 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Game Log](https://www.nba.com/stats/player/2544/boxscores-traditional) +#' ```r +#' nba_playergamelog(player_id = '2544') +#' ``` nba_playergamelog <- function( date_from = '', date_to = '', league_id = '00', player_id = '2544', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', ...){ @@ -551,11 +607,11 @@ nba_playergamelog <- function( } #' **Get NBA Stats API Player Game Logs** -#' @name p_gamelogs +#' @name nba_playergamelogs NULL #' @title #' **Get NBA Stats API Player Game Logs** -#' @rdname p_gamelogs +#' @rdname nba_playergamelogs #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -583,6 +639,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Game Logs](https://www.nba.com/stats/player/2544/boxscores-traditional) +#' ```r +#' nba_playergamelogs(player_id = '2544') +#' ``` nba_playergamelogs <- function( date_from = '', date_to = '', @@ -598,7 +659,7 @@ nba_playergamelogs <- function( per_mode = 'Totals', period = 0, player_id = '2544', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '', @@ -653,11 +714,11 @@ nba_playergamelogs <- function( #' **Get NBA Stats API Player Game Streak Finder** -#' @name pg_streak +#' @name nba_playergamestreakfinder NULL #' @title #' **Get NBA Stats API Player Game Streak Finder** -#' @rdname pg_streak +#' @rdname nba_playergamestreakfinder #' @author Saiem Gilani #' @param active_streaks_only active_streaks_only #' @param conference conference @@ -754,6 +815,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_playergamestreakfinder() +#' ``` nba_playergamestreakfinder <- function( active_streaks_only = '', @@ -836,7 +901,7 @@ nba_playergamestreakfinder <- function( po_round = '', player_id = '', rookie_year = '', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', starter_bench = '', @@ -963,11 +1028,11 @@ nba_playergamestreakfinder <- function( #' **Get NBA Stats API Player Next N Games** -#' @name p_n_g +#' @name nba_playernextngames NULL #' @title #' **Get NBA Stats API Player Next N Games** -#' @rdname p_n_g +#' @rdname nba_playernextngames #' @author Saiem Gilani #' @param league_id League - default: '00'. Other options include '10': WNBA, '20': G-League #' @param number_of_games N in number of games @@ -980,11 +1045,15 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_playernextngames(player_id = '2544') +#' ``` nba_playernextngames <- function( league_id = '', number_of_games = 2147483647, player_id = '2544', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', ...){ @@ -1022,11 +1091,11 @@ nba_playernextngames <- function( #' **Get NBA Stats API Player Profile V2** -#' @name playerprofilev2 +#' @name nba_playerprofilev2 NULL #' @title #' **Get NBA Stats API Player Profile V2** -#' @rdname playerprofilev2 +#' @rdname nba_playerprofilev2 #' @author Saiem Gilani #' @param league_id League - default: '00'. Other options include '10': WNBA, '20': G-League #' @param player_id Player ID @@ -1039,6 +1108,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Profile](https://www.nba.com/stats/player/2544/career) +#' ```r +#' nba_playerprofilev2(player_id = '2544') +#' ``` nba_playerprofilev2 <- function( league_id = '', per_mode = 'Totals', @@ -1074,11 +1148,11 @@ nba_playerprofilev2 <- function( #' **Get NBA Stats API Player vs Player** -#' @name playervsplayer +#' @name nba_playervsplayer NULL #' @title #' **Get NBA Stats API Player vs Player** -#' @rdname playervsplayer +#' @rdname nba_playervsplayer #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -1109,6 +1183,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_playervsplayer(player_id = '2544', vs_player_id = '203076') +#' ``` nba_playervsplayer <- function( date_from = '', date_to = '', @@ -1126,7 +1204,7 @@ nba_playervsplayer <- function( player_id = '2544', plus_minus = 'N', rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', vs_conference = '', @@ -1182,11 +1260,11 @@ nba_playervsplayer <- function( #' **Get NBA Stats API Player Compare** -#' @name playercompare +#' @name nba_playercompare NULL #' @title #' **Get NBA Stats API Player Compare** -#' @rdname playercompare +#' @rdname nba_playercompare #' @author Saiem Gilani #' @param conference conference #' @param date_from date_from @@ -1218,6 +1296,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_playercompare(player_id_list = '202681,203078,2544,201567,203954', vs_player_id_list = '201566,201939,201935,201142,203076') +#' ``` nba_playercompare <- function( conference = '', date_from = '', diff --git a/R/nba_stats_player_dash.R b/R/nba_stats_player_dash.R index f3aa8eba..5e2cb1f0 100644 --- a/R/nba_stats_player_dash.R +++ b/R/nba_stats_player_dash.R @@ -1,11 +1,11 @@ ## Player Dashboard parameters are the same #' **Get NBA Stats API Player Dashboard by Clutch Splits** -#' @name pbyclutch +#' @name nba_playerdashboardbyclutch NULL #' @title #' **Get NBA Stats API Player Dashboard by Clutch Splits** -#' @rdname pbyclutch +#' @rdname nba_playerdashboardbyclutch #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -39,6 +39,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Clutch Stats Dashboard](https://www.nba.com/stats/players/clutch-traditional) +#' ```r +#' nba_playerdashboardbyclutch(player_id = '2544', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_playerdashboardbyclutch <- function( date_from = '', date_to = '', @@ -57,7 +62,7 @@ nba_playerdashboardbyclutch <- function( player_id = '2544', plus_minus = 'N', rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -114,11 +119,11 @@ nba_playerdashboardbyclutch <- function( #' **Get NBA Stats API Player Dashboard by Game Splits** -#' @name pbygamesplits +#' @name nba_playerdashboardbygamesplits NULL #' @title #' **Get NBA Stats API Player Dashboard by Game Splits** -#' @rdname pbygamesplits +#' @rdname nba_playerdashboardbygamesplits #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -149,6 +154,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Stats Dashboard by Game Splits](https://www.nba.com/stats/player/2544/traditional?Split=ingame) +#' ```r +#' nba_playerdashboardbygamesplits(player_id = '2544', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_playerdashboardbygamesplits <- function( date_from = '', date_to = '', @@ -167,7 +177,7 @@ nba_playerdashboardbygamesplits <- function( player_id = '2544', plus_minus = 'N', rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -225,11 +235,11 @@ nba_playerdashboardbygamesplits <- function( #' **Get NBA Stats API Player Dashboard by General Splits** -#' @name pbygeneralsplits +#' @name nba_playerdashboardbygeneralsplits NULL #' @title #' **Get NBA Stats API Player Dashboard by General Splits** -#' @rdname pbygeneralsplits +#' @rdname nba_playerdashboardbygeneralsplits #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -261,6 +271,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Stats Dashboard by General Splits](https://www.nba.com/stats/player/2544/traditional) +#' ```r +#' nba_playerdashboardbygeneralsplits(player_id = '2544', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_playerdashboardbygeneralsplits <- function( date_from = '', date_to = '', @@ -279,7 +294,7 @@ nba_playerdashboardbygeneralsplits <- function( player_id = '2544', plus_minus = 'N', rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -337,11 +352,11 @@ nba_playerdashboardbygeneralsplits <- function( #' **Get NBA Stats API Player Dashboard by Last N Games** -#' @name pbylastngames +#' @name nba_playerdashboardbylastngames NULL #' @title #' **Get NBA Stats API Player Dashboard by Last N Games** -#' @rdname pbylastngames +#' @rdname nba_playerdashboardbylastngames #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -373,6 +388,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Stats Dashboard by Last N Games](https://www.nba.com/stats/player/2544/traditional?Split=lastn) +#' ```r +#' nba_playerdashboardbylastngames(player_id = '2544', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_playerdashboardbylastngames <- function( date_from = '', date_to = '', @@ -391,7 +411,7 @@ nba_playerdashboardbylastngames <- function( player_id = '2544', plus_minus = 'N', rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -448,11 +468,11 @@ nba_playerdashboardbylastngames <- function( #' **Get NBA Stats API Player Dashboard by Opponent** -#' @name pbyopponent +#' @name nba_playerdashboardbyopponent NULL #' @title #' **Get NBA Stats API Player Dashboard by Opponent** -#' @rdname pbyopponent +#' @rdname nba_playerdashboardbyopponent #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -483,6 +503,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Stats Dashboard by Opponent](https://www.nba.com/stats/player/2544/traditional?Split=opp) +#' ```r +#' nba_playerdashboardbyopponent(player_id = '2544', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_playerdashboardbyopponent <- function( date_from = '', date_to = '', @@ -501,7 +526,7 @@ nba_playerdashboardbyopponent <- function( player_id = '2544', plus_minus = 'N', rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -557,11 +582,11 @@ nba_playerdashboardbyopponent <- function( #' **Get NBA Stats API Player Dashboard by Shooting Splits** -#' @name pbyshootingsplits +#' @name nba_playerdashboardbyshootingsplits NULL #' @title #' **Get NBA Stats API Player Dashboard by Shooting Splits** -#' @rdname pbyshootingsplits +#' @rdname nba_playerdashboardbyshootingsplits #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -593,6 +618,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Stats Dashboard by Shooting Splits](https://www.nba.com/stats/player/2544/shooting) +#' ```r +#' nba_playerdashboardbyshootingsplits(player_id = '2544', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_playerdashboardbyshootingsplits <- function( date_from = '', date_to = '', @@ -611,7 +641,7 @@ nba_playerdashboardbyshootingsplits <- function( player_id = '2544', plus_minus = 'N', rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -667,11 +697,11 @@ nba_playerdashboardbyshootingsplits <- function( #' **Get NBA Stats API Player Dashboard by Team Performance** -#' @name pbyteamperformance +#' @name nba_playerdashboardbyteamperformance NULL #' @title #' **Get NBA Stats API Player Dashboard by Team Performance** -#' @rdname pbyteamperformance +#' @rdname nba_playerdashboardbyteamperformance #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -703,6 +733,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Stats Dashboard by Team Performance](https://www.nba.com/stats/player/2544/traditional?Split=teamperf&PerMode=PerGame) +#' ```r +#' nba_playerdashboardbyteamperformance(player_id = '2544', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_playerdashboardbyteamperformance <- function( date_from = '', date_to = '', @@ -721,7 +756,7 @@ nba_playerdashboardbyteamperformance <- function( player_id = '2544', plus_minus = 'N', rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -777,11 +812,11 @@ nba_playerdashboardbyteamperformance <- function( #' **Get NBA Stats API Player Dashboard Year over Year** -#' @name pbyyearoveryear +#' @name nba_playerdashboardbyyearoveryear NULL #' @title #' **Get NBA Stats API Player Dashboard Year over Year** -#' @rdname pbyyearoveryear +#' @rdname nba_playerdashboardbyyearoveryear #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -812,6 +847,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Stats Dashboard by Team Performance](https://www.nba.com/stats/player/2544/traditional?Split=yoy&PerMode=PerGame) +#' ```r +#' nba_playerdashboardbyyearoveryear(player_id = '2544', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_playerdashboardbyyearoveryear <- function( date_from = '', date_to = '', @@ -830,7 +870,7 @@ nba_playerdashboardbyyearoveryear <- function( player_id = '2544', plus_minus = 'N', rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -886,11 +926,11 @@ nba_playerdashboardbyyearoveryear <- function( } #' **Get NBA Stats API Player Dashboard Player Tracking - Passing** -#' @name pptpass +#' @name nba_playerdashptpass NULL #' @title #' **Get NBA Stats API Player Dashboard Player Tracking - Passing** -#' @rdname pptpass +#' @rdname nba_playerdashptpass #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -914,6 +954,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Tracking (Second Spectrum) Stats - Passing](https://www.nba.com/stats/player/2544/passes-dash) +#' ```r +#' nba_playerdashptpass(player_id = '2544', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_playerdashptpass <- function( date_from = '', date_to = '', @@ -925,7 +970,7 @@ nba_playerdashptpass <- function( outcome = '', per_mode = 'Totals', player_id = '2544', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '0', @@ -974,11 +1019,11 @@ nba_playerdashptpass <- function( #' **Get NBA Stats API Player Dashboard Player Tracking - Rebounding** -#' @name pptreb +#' @name nba_playerdashptreb NULL #' @title #' **Get NBA Stats API Player Dashboard Player Tracking - Rebounding** -#' @rdname pptreb +#' @rdname nba_playerdashptreb #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -1005,6 +1050,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Tracking (Second Spectrum) Stats - Rebounding](https://www.nba.com/stats/player/2544/rebounds-dash) +#' ```r +#' nba_playerdashptreb(player_id = '2544', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_playerdashptreb <- function( date_from = '', date_to = '', @@ -1018,7 +1068,7 @@ nba_playerdashptreb <- function( per_mode = 'Totals', period = 0, player_id = '2544', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '0', @@ -1070,11 +1120,11 @@ nba_playerdashptreb <- function( #' **Get NBA Stats API Player Dashboard Player Tracking - Defense** -#' @name pptshotdefend +#' @name nba_playerdashptshotdefend NULL #' @title #' **Get NBA Stats API Player Dashboard Player Tracking - Defense** -#' @rdname pptshotdefend +#' @rdname nba_playerdashptshotdefend #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -1100,6 +1150,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Tracking (Second Spectrum) Stats - Defending](https://www.nba.com/stats/player/2544/defense-dash) +#' ```r +#' nba_playerdashptshotdefend(player_id = '2544', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_playerdashptshotdefend <- function( date_from = '', date_to = '', @@ -1113,7 +1168,7 @@ nba_playerdashptshotdefend <- function( per_mode = 'Totals', period = 0, player_id = '2544', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '0', @@ -1164,11 +1219,11 @@ nba_playerdashptshotdefend <- function( #' **Get NBA Stats API Player Dashboard Player Tracking - Shots** -#' @name pptshots +#' @name nba_playerdashptshots NULL #' @title #' **Get NBA Stats API Player Dashboard Player Tracking - Shots** -#' @rdname pptshots +#' @rdname nba_playerdashptshots #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -1195,6 +1250,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Tracking (Second Spectrum) Stats - Shooting](https://www.nba.com/stats/player/2544/shots-dash) +#' ```r +#' nba_playerdashptshots(player_id = '2544', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_playerdashptshots <- function( date_from = '', date_to = '', @@ -1208,7 +1268,7 @@ nba_playerdashptshots <- function( per_mode = 'Totals', period = 0, player_id = '2544', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '0', @@ -1256,3 +1316,72 @@ nba_playerdashptshots <- function( ) return(df_list) } + + + + +#' **Get NBA Stats API Synergy Play Type Stats** +#' @name nba_synergyplaytypes +NULL +#' @title +#' **Get NBA Stats API Synergy Play Type Stats** +#' @rdname nba_synergyplaytypes +#' @author Saiem Gilani +#' @param league_id league_id +#' @param per_mode per_mode +#' @param play_type play_type - 'Isolation', 'Transition', 'PRBallHandler', 'PRRollman', 'Postup', +#' 'Spotup', 'Handoff', 'Cut', 'OffScreen', 'OffRebound', 'Misc' +#' @param player_or_team player_or_team ('P' or 'T') +#' @param season_type season_type +#' @param season season +#' @param type_grouping type_grouping - Offensive, Defensive +#' @param ... Additional arguments passed to an underlying function like httr. +#' @importFrom jsonlite fromJSON toJSON +#' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble +#' @import rvest +#' @export +#' @details +#' [Synergy Play Type Stats](https://www.nba.com/stats/teams/isolation) +#' ```r +#' nba_synergyplaytypes(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` +nba_synergyplaytypes <- function( + league_id = '00', + per_mode = 'PerGame', + play_type = 'Isolation', + player_or_team = 'P', + season = year_to_season(most_recent_nba_season() - 1), + season_type = 'Regular Season', + type_grouping = 'Offensive', + ...){ + season_type <- gsub(' ','+',season_type) + version <- "synergyplaytypes" + endpoint <- nba_endpoint(version) + + full_url <- paste0(endpoint, + "?LeagueID=", league_id, + "&PerMode=", per_mode, + "&PlayType=", play_type, + "&PlayerOrTeam=", player_or_team, + "&SeasonType=", season_type, + "&SeasonYear=", season, + "&TypeGrouping=", type_grouping) + + tryCatch( + expr = { + + resp <- request_with_proxy(url = full_url, ...) + + df_list <- nba_stats_map_result_sets(resp) + + }, + error = function(e) { + message(glue::glue("{Sys.time()}: Invalid arguments or no Synergy play types data for {season} available!")) + }, + warning = function(w) { + }, + finally = { + } + ) + return(df_list) +} diff --git a/R/nba_stats_roster.R b/R/nba_stats_roster.R index bb768bde..8daf9df4 100644 --- a/R/nba_stats_roster.R +++ b/R/nba_stats_roster.R @@ -1,9 +1,9 @@ #' **Get NBA Stats API All Players** -#' @name allplayers +#' @name nba_commonallplayers NULL #' @title #' **Get NBA Stats API All Players** -#' @rdname allplayers +#' @rdname nba_commonallplayers #' @author Saiem Gilani #' @param is_only_current_season is_only_current_season #' @param league_id league_id @@ -14,10 +14,15 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [All Players](https://www.nba.com/players) +#' ```r +#' nba_commonallplayers(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_commonallplayers <- function( is_only_current_season = 0, league_id = '00', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), ...){ version <- "commonallplayers" @@ -46,11 +51,11 @@ nba_commonallplayers <- function( return(df_list) } #' **Get NBA Stats API Player Info** -#' @name commonplayerinfo +#' @name nba_commonplayerinfo NULL #' @title #' **Get NBA Stats API Player Info** -#' @rdname commonplayerinfo +#' @rdname nba_commonplayerinfo #' @author Saiem Gilani #' @param league_id league_id #' @param player_id player_id @@ -60,6 +65,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Player Info](https://www.nba.com/stats/player/2544) +#' ```r +#' nba_commonplayerinfo(league_id = '00', player_id = '2544') +#' ``` nba_commonplayerinfo <- function( league_id = '00', player_id = '2544', @@ -91,11 +101,11 @@ nba_commonplayerinfo <- function( } #' **Get NBA Stats API Playoff Series** -#' @name commonplayoffseries +#' @name nba_commonplayoffseries NULL #' @title #' **Get NBA Stats API Playoff Series** -#' @rdname commonplayoffseries +#' @rdname nba_commonplayoffseries #' @author Saiem Gilani #' @param league_id league_id #' @param season season @@ -106,9 +116,13 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_commonplayoffseries(league_id = '00', season = year_to_season(most_recent_nba_season() - 2)) +#' ``` nba_commonplayoffseries <- function( league_id = '00', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 2), series_id = '', ...){ @@ -140,11 +154,11 @@ nba_commonplayoffseries <- function( #' **Get NBA Stats API Team Roster** -#' @name commonteamroster +#' @name nba_commonteamroster NULL #' @title #' **Get NBA Stats API Team Roster** -#' @rdname commonteamroster +#' @rdname nba_commonteamroster #' @author Saiem Gilani #' @param league_id league_id #' @param season season @@ -155,9 +169,14 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Roster](https://www.nba.com/stats/team/1610612756) +#' ```r +#' nba_commonteamroster(season = year_to_season(most_recent_nba_season() - 1), team_id = '1610612739') +#' ``` nba_commonteamroster <- function( league_id = '00', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), team_id = '1610612739', ...){ diff --git a/R/nba_stats_scoreboard.R b/R/nba_stats_scoreboard.R index dce9eeed..4ff72963 100644 --- a/R/nba_stats_scoreboard.R +++ b/R/nba_stats_scoreboard.R @@ -1,12 +1,137 @@ +#' **Get NBA Stats API Season Schedule** +#' @name nba_schedule +NULL +#' @title +#' **Get NBA Stats API Season Schedule** +#' @rdname nba_schedule +#' @author Saiem Gilani +#' @param league_id League - default: '00'. Other options include '10': WNBA, '20': G-League +#' @param season Season +#' @param ... Additional arguments passed to an underlying function like httr. +#' @importFrom jsonlite fromJSON toJSON +#' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble +#' @import rvest +#' @return Returns a tibble with the following columns: +#' +#' |col_name |types | +#' |:------------------|:---------| +#' |game_date |character | +#' |game_id |character | +#' |game_code |character | +#' |game_status |integer | +#' |game_status_text |character | +#' |game_sequence |integer | +#' |game_date_est |character | +#' |game_time_est |character | +#' |game_date_time_est |character | +#' |game_date_utc |character | +#' |game_time_utc |character | +#' |game_date_time_utc |character | +#' |away_team_time |character | +#' |home_team_time |character | +#' |day |character | +#' |month_num |integer | +#' |week_number |integer | +#' |week_name |character | +#' |if_necessary |character | +#' |series_game_number |character | +#' |series_text |character | +#' |arena_name |character | +#' |arena_state |character | +#' |arena_city |character | +#' |postponed_status |character | +#' |branch_link |character | +#' |game_subtype |character | +#' |home_team_id |integer | +#' |home_team_name |character | +#' |home_team_city |character | +#' |home_team_tricode |character | +#' |home_team_slug |character | +#' |home_team_wins |integer | +#' |home_team_losses |integer | +#' |home_team_score |integer | +#' |home_team_seed |integer | +#' |away_team_id |integer | +#' |away_team_name |character | +#' |away_team_city |character | +#' |away_team_tricode |character | +#' |away_team_slug |character | +#' |away_team_wins |integer | +#' |away_team_losses |integer | +#' |away_team_score |integer | +#' |away_team_seed |integer | +#' |season |character | +#' |league_id |character | +#' +#' @export +#' @details +#' ```r +#' nba_schedule(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` +nba_schedule <- function( + league_id = '00', + season = year_to_season(most_recent_nba_season() - 1), + ...){ + + + version <- "scheduleleaguev2" + full_url <- nba_endpoint(version) + params <- list( + LeagueID = league_id, + Season = season + ) + tryCatch( + expr = { + + resp <- request_with_proxy(url = full_url, params = params, ...) + + league_sched <- resp %>% + purrr::pluck("leagueSchedule") + games <- league_sched %>% + purrr::pluck("gameDates") %>% + tidyr::unnest("games") %>% + tidyr::unnest("awayTeam", names_sep = "_") %>% + tidyr::unnest("homeTeam", names_sep = "_") %>% + dplyr::select(-dplyr::any_of(c("broadcasters", "pointsLeaders"))) %>% + janitor::clean_names() + colnames(games) <- gsub('team_team', 'team', colnames(games)) + games$game_id <- unlist(purrr::map(games$game_id,function(x){ + pad_id(x) + })) + games$season <- league_sched$seasonYear + games$league_id <- league_sched$leagueId + games <- games %>% + dplyr::mutate( + season_type_id = substr(.data$game_id, 3, 3), + season_type_description = dplyr::case_when( + .data$season_type_id == 1 ~ "Pre-Season", + .data$season_type_id == 2 ~ "Regular Season", + .data$season_type_id == 3 ~ "All-Star", + .data$season_type_id == 4 ~ "Playoffs", + .data$season_type_id == 5 ~ "Play-In Game"), + game_date = lubridate::ymd(substring(.data$game_date,1,10))) + + }, + error = function(e) { + message(glue::glue("{Sys.time()}: Invalid arguments or no league schedule data for {season} available!")) + }, + warning = function(w) { + }, + finally = { + } + ) + return(games) +} + #' **Get NBA Stats API Scoreboard** -#' @name scoreboard +#' @name nba_scoreboard NULL #' @title #' **Get NBA Stats API Scoreboard** -#' @rdname scoreboard +#' @rdname nba_scoreboard #' @author Saiem Gilani #' @param league_id League - default: '00'. Other options include '10': WNBA, '20': G-League #' @param game_date Game Date @@ -18,6 +143,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_scoreboard(league_id = '00', game_date = '2021-07-20') +#' ``` nba_scoreboard <- function( league_id = '00', game_date = '2021-07-20', @@ -53,11 +182,11 @@ nba_scoreboard <- function( #' **Get NBA Stats API Scoreboard V2** -#' @name scoreboardv2 +#' @name nba_scoreboardv2 NULL #' @title #' **Get NBA Stats API Scoreboard V2** -#' @rdname scoreboardv2 +#' @rdname nba_scoreboardv2 #' @author Saiem Gilani #' @param league_id League - default: '00'. Other options include '10': WNBA, '20': G-League #' @param game_date Game Date @@ -70,6 +199,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_scoreboardv2(league_id = '00', game_date = '2021-07-20') +#' ``` nba_scoreboardv2 <- function( league_id = '00', game_date = '2021-07-20', @@ -107,11 +240,11 @@ nba_scoreboardv2 <- function( #' **Get NBA Stats API Win Probability PBP** -#' @name winprobabilitypbp +#' @name nba_winprobabilitypbp NULL #' @title #' **Get NBA Stats API Win Probability PBP** -#' @rdname winprobabilitypbp +#' @rdname nba_winprobabilitypbp #' @author Saiem Gilani #' @param game_id Game ID #' @param run_type Run Type @@ -121,6 +254,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_winprobabilitypbp(game_id = '0021700807', run_type = 'each second') +#' ``` nba_winprobabilitypbp <- function( game_id = '0021700807', run_type = 'each second', diff --git a/R/nba_stats_shotchart.R b/R/nba_stats_shotchart.R index 9656ae24..5a906bd6 100644 --- a/R/nba_stats_shotchart.R +++ b/R/nba_stats_shotchart.R @@ -1,9 +1,9 @@ #' **Get NBA Stats API Shot Chart Detail** -#' @name sc +#' @name nba_shotchartdetail NULL #' @title #' **Get NBA Stats API Shot Chart Detail** -#' @rdname sc +#' @rdname nba_shotchartdetail #' @author Saiem Gilani #' @param context_measure context_measure #' @param date_from date_from @@ -32,6 +32,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_shotchartdetail(league_id = '00', player_id = '202696', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_shotchartdetail <- function( context_measure = 'FGA', date_from = '', @@ -48,7 +52,7 @@ nba_shotchartdetail <- function( player_id = '202696', player_position = '', rookie_year = '', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = 0, @@ -107,11 +111,11 @@ nba_shotchartdetail <- function( #' **Get NBA Stats API Shot Chart League-Wide** -#' @name sc_lw +#' @name nba_shotchartleaguewide NULL #' @title #' **Get NBA Stats API Shot Chart League-Wide** -#' @rdname sc_lw +#' @rdname nba_shotchartleaguewide #' @author Saiem Gilani #' @param league_id League - default: '00'. Other options include '10': WNBA, '20': G-League #' @param season season @@ -121,6 +125,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_shotchartleaguewide(league_id = '00', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_shotchartleaguewide <- function( league_id = '00', season = year_to_season(most_recent_nba_season() - 1), @@ -152,12 +160,13 @@ nba_shotchartleaguewide <- function( ) return(df_list) } + #' **Get NBA Stats API Shot Chart for Lineups** -#' @name sc_lineups +#' @name nba_shotchartlineupdetail NULL #' @title #' **Get NBA Stats API Shot Chart for Lineups** -#' @rdname sc_lineups +#' @rdname nba_shotchartlineupdetail #' @author Saiem Gilani #' @param ahead_behind ahead_behind #' @param cfid cfid @@ -175,7 +184,7 @@ NULL #' @param game_event_id game_event_id #' @param game_id game_id #' @param game_segment game_segment -#' @param group_id_2 group_id_2 +#' @param group_id2 group_id2 #' @param group_mode group_mode #' @param group_quantity group_quantity #' @param last_n_games last_n_games @@ -221,6 +230,12 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_shotchartlineupdetail(group_id = '-202689-203493-203501-1626174-1627827-', +#' group_id2 = '-202689-203493-203501-1626174-1627827-', +#' season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_shotchartlineupdetail <- function( ahead_behind = '', cfid = '', @@ -238,7 +253,7 @@ nba_shotchartlineupdetail <- function( game_event_id = '', game_id = '', game_segment = '', - group_id_2 = '-202689-203493-203501-1626174-1627827-', + group_id2 = '-202689-203493-203501-1626174-1627827-', group_mode = '', group_quantity = '5', last_n_games = '0', @@ -301,7 +316,7 @@ nba_shotchartlineupdetail <- function( GameEventID = game_event_id, GameID = game_id, GameSegment = game_segment, - GroupID = group_id_2, + GroupID = group_id2, GroupMode = group_mode, GroupQuantity = group_quantity, LastNGames = last_n_games, diff --git a/R/nba_stats_team.R b/R/nba_stats_team.R index b9516e92..aeef5bc0 100644 --- a/R/nba_stats_team.R +++ b/R/nba_stats_team.R @@ -1,9 +1,9 @@ #' **Get NBA Stats API Team Details** -#' @name t_details +#' @name nba_teamdetails NULL #' @title #' **Get NBA Stats API Team Details** -#' @rdname t_details +#' @rdname nba_teamdetails #' @author Saiem Gilani #' @param team_id Team ID #' @param ... Additional arguments passed to an underlying function like httr. @@ -14,6 +14,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_teamdetails(team_id = '1610612749') +#' ``` nba_teamdetails <- function( team_id = '1610612749', ...){ @@ -44,11 +48,11 @@ nba_teamdetails <- function( #' **Get NBA Stats API Team Estimated Metrics** -#' @name t_est_metr +#' @name nba_teamestimatedmetrics NULL #' @title #' **Get NBA Stats API Team Estimated Metrics** -#' @rdname t_est_metr +#' @rdname nba_teamestimatedmetrics #' @author Saiem Gilani #' @param season Season - format 2020-21 #' @param season_type Season Type - Regular Season, Playoffs, All-Star @@ -59,9 +63,14 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Estimated Metrics](https://www.nba.com/stats/teams/estimated-advanced) +#' ```r +#' nba_teamestimatedmetrics() +#' ``` nba_teamestimatedmetrics <- function( league_id = '00', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', ...){ @@ -96,11 +105,11 @@ nba_teamestimatedmetrics <- function( #' **Get NBA Stats API Team Game Log** -#' @name t_gamelog +#' @name nba_teamgamelog NULL #' @title #' **Get NBA Stats API Team Game Log** -#' @rdname t_gamelog +#' @rdname nba_teamgamelog #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -114,11 +123,16 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Teams Game Log](https://www.nba.com/stats/team/1610612749/boxscores) +#' ```r +#' nba_teamgamelog(team_id = '1610612749') +#' ``` nba_teamgamelog <- function( date_from = '', date_to = '', league_id = '00', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', team_id = '1610612749', ...){ @@ -155,11 +169,11 @@ nba_teamgamelog <- function( #' **Get NBA Stats API Team Game Logs** -#' @name t_gamelogs +#' @name nba_teamgamelogs NULL #' @title #' **Get NBA Stats API Team Game Logs** -#' @rdname t_gamelogs +#' @rdname nba_teamgamelogs #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -187,6 +201,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Teams Game Log](https://www.nba.com/stats/team/1610612749/boxscores) +#' ```r +#' nba_teamgamelogs(team_id = '1610612749') +#' ``` nba_teamgamelogs <- function( date_from = '', date_to = '', @@ -202,7 +221,7 @@ nba_teamgamelogs <- function( per_mode = 'Totals', period = 0, player_id = '', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '1610612749', @@ -257,11 +276,11 @@ nba_teamgamelogs <- function( #' **Get NBA Stats API Team Historical Leaders** -#' @name thist_leaders +#' @name nba_teamhistoricalleaders NULL #' @title #' **Get NBA Stats API Team Historical Leaders** -#' @rdname thist_leaders +#' @rdname nba_teamhistoricalleaders #' @author Saiem Gilani #' @param league_id league_id #' @param season_id season_id @@ -272,9 +291,13 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_teamhistoricalleaders(team_id = '1610612749') +#' ``` nba_teamhistoricalleaders <- function( league_id = '00', - season_id = '2020', + season_id = '22022', team_id = '1610612749', ...){ @@ -306,11 +329,11 @@ nba_teamhistoricalleaders <- function( #' **Get NBA Stats API Team Common Info** -#' @name teaminfo +#' @name nba_teaminfocommon NULL #' @title #' **Get NBA Stats API Team Common Info** -#' @rdname teaminfo +#' @rdname nba_teaminfocommon #' @author Saiem Gilani #' @param league_id League - default: '00'. Other options include '10': WNBA, '20': G-League #' @param team_id Team ID @@ -322,9 +345,13 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_teaminfocommon(team_id = '1610612749') +#' ``` nba_teaminfocommon <- function( league_id = '00', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_type = 'Regular Season', team_id = '1610612749', ...){ @@ -360,11 +387,11 @@ nba_teaminfocommon <- function( #' **Get NBA Stats API Team Player On/Off Details** -#' @name tp_onoff_det +#' @name nba_teamplayeronoffdetails NULL #' @title #' **Get NBA Stats API Team Player On/Off Details** -#' @rdname tp_onoff_det +#' @rdname nba_teamplayeronoffdetails #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -396,6 +423,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_teamplayeronoffdetails(team_id = '1610612749') +#' ``` nba_teamplayeronoffdetails <- function( date_from = '', date_to = '', @@ -413,7 +444,7 @@ nba_teamplayeronoffdetails <- function( per_mode = 'Totals', period = 0, rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -470,11 +501,11 @@ nba_teamplayeronoffdetails <- function( #' **Get NBA Stats API Team Player On/Off Summary** -#' @name tp_onoffsummary +#' @name nba_teamplayeronoffsummary NULL #' @title #' **Get NBA Stats API Team Player On/Off Summary** -#' @rdname tp_onoffsummary +#' @rdname nba_teamplayeronoffsummary #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -506,6 +537,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_teamplayeronoffsummary(team_id = '1610612749') +#' ``` nba_teamplayeronoffsummary <- function( date_from = '', date_to = '', @@ -523,7 +558,7 @@ nba_teamplayeronoffsummary <- function( per_mode = 'Totals', period = 0, rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -581,11 +616,11 @@ nba_teamplayeronoffsummary <- function( #' **Get NBA Stats API Team Player Dashboard** -#' @name tp +#' @name nba_teamplayerdashboard NULL #' @title #' **Get NBA Stats API Team Player Dashboard** -#' @rdname tp +#' @rdname nba_teamplayerdashboard #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -616,6 +651,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_teamplayerdashboard(team_id = '1610612749') +#' ``` nba_teamplayerdashboard <- function( date_from = '', date_to = '', @@ -633,7 +672,7 @@ nba_teamplayerdashboard <- function( per_mode = 'Totals', period = 0, rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -691,11 +730,11 @@ nba_teamplayerdashboard <- function( #' **Get NBA Stats API Team Year by Year Stats** -#' @name t_yby_stats +#' @name nba_teamyearbyyearstats NULL #' @title #' **Get NBA Stats API Team Year by Year Stats** -#' @rdname t_yby_stats +#' @rdname nba_teamyearbyyearstats #' @author Saiem Gilani #' @param league_id League - default: '00'. Other options include '10': WNBA, '20': G-League #' @param per_mode Per Mode @@ -707,6 +746,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Year by Year Stats](https://www.nba.com/stats/team/1610612756/seasons) +#' ```r +#' nba_teamyearbyyearstats(team_id = '1610612749') +#' ``` nba_teamyearbyyearstats <- function( league_id = '00', per_mode = 'Totals', @@ -745,11 +789,11 @@ nba_teamyearbyyearstats <- function( #' **Get NBA Stats API Team vs Player** -#' @name t_vs_p +#' @name nba_teamvsplayer NULL #' @title #' **Get NBA Stats API Team vs Player** -#' @rdname t_vs_p +#' @rdname nba_teamvsplayer #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -784,6 +828,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_teamvsplayer(team_id = '1610612749', vs_player_id = '2544') +#' ``` nba_teamvsplayer <- function( date_from = '', date_to = '', @@ -802,7 +850,7 @@ nba_teamvsplayer <- function( player_id = '', plus_minus = 'N', rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -865,11 +913,11 @@ nba_teamvsplayer <- function( #' **Get NBA Stats API Team Game Streak Finder** -#' @name tg_streak +#' @name nba_teamgamestreakfinder NULL #' @title #' **Get NBA Stats API Team Game Streak Finder** -#' @rdname tg_streak +#' @rdname nba_teamgamestreakfinder #' @author Saiem Gilani #' @param active_streaks_only active_streaks_only #' @param active_teams_only active_teams_only @@ -1065,6 +1113,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_teamgamestreakfinder() +#' ``` nba_teamgamestreakfinder <- function( active_streaks_only = '', @@ -1225,7 +1277,7 @@ nba_teamgamestreakfinder <- function( min_games = '', outcome = '', po_round = '', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '', diff --git a/R/nba_stats_team_dash.R b/R/nba_stats_team_dash.R index 90571b8b..aaf07044 100644 --- a/R/nba_stats_team_dash.R +++ b/R/nba_stats_team_dash.R @@ -1,11 +1,11 @@ ## Team Dashboard parameters are the same #' **Get NBA Stats API Team Dashboard by Clutch Splits** -#' @name tbyclutch +#' @name nba_teamdashboardbyclutch NULL #' @title #' **Get NBA Stats API Team Dashboard by Clutch Splits** -#' @rdname tbyclutch +#' @rdname nba_teamdashboardbyclutch #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -40,6 +40,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Clutch Stats Dashboard](https://www.nba.com/stats/teams/clutch-traditional) +#' ```r +#' nba_teamdashboardbyclutch(team_id = '1610612749', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_teamdashboardbyclutch <- function( date_from = '', date_to = '', @@ -57,7 +62,7 @@ nba_teamdashboardbyclutch <- function( per_mode = 'Totals', period = 0, rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -114,11 +119,11 @@ nba_teamdashboardbyclutch <- function( #' **Get NBA Stats API Team Dashboard by Game Splits** -#' @name tbygamesplits +#' @name nba_teamdashboardbygamesplits NULL #' @title #' **Get NBA Stats API Team Dashboard by Game Splits** -#' @rdname tbygamesplits +#' @rdname nba_teamdashboardbygamesplits #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -151,6 +156,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Dashboard by Game Splits](https://www.nba.com/stats/team/1610612749/traditional?Split=ingame) +#' ```r +#' nba_teamdashboardbygamesplits(team_id = '1610612749', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_teamdashboardbygamesplits <- function( date_from = '', date_to = '', @@ -168,7 +178,7 @@ nba_teamdashboardbygamesplits <- function( per_mode = 'Totals', period = 0, rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -226,11 +236,11 @@ nba_teamdashboardbygamesplits <- function( #' **Get NBA Stats API Team Dashboard by General Splits** -#' @name tbygeneralsplits +#' @name nba_teamdashboardbygeneralsplits NULL #' @title #' **Get NBA Stats API Team Dashboard by General Splits** -#' @rdname tbygeneralsplits +#' @rdname nba_teamdashboardbygeneralsplits #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -263,6 +273,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Dashboard by General Splits](https://www.nba.com/stats/team/1610612749/traditional?Split=general) +#' ```r +#' nba_teamdashboardbygeneralsplits(team_id = '1610612749', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_teamdashboardbygeneralsplits <- function( date_from = '', date_to = '', @@ -280,7 +295,7 @@ nba_teamdashboardbygeneralsplits <- function( per_mode = 'Totals', period = 0, rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -338,11 +353,11 @@ nba_teamdashboardbygeneralsplits <- function( #' **Get NBA Stats API Team Dashboard by Last N Games** -#' @name tbylastngames +#' @name nba_teamdashboardbylastngames NULL #' @title #' **Get NBA Stats API Team Dashboard by Last N Games** -#' @rdname tbylastngames +#' @rdname nba_teamdashboardbylastngames #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -375,6 +390,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Dashboard by Last N Games](https://www.nba.com/stats/team/1610612749/traditional?Split=lastn) +#' ```r +#' nba_teamdashboardbylastngames(team_id = '1610612749', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_teamdashboardbylastngames <- function( date_from = '', date_to = '', @@ -392,7 +412,7 @@ nba_teamdashboardbylastngames <- function( per_mode = 'Totals', period = 0, rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -450,11 +470,11 @@ nba_teamdashboardbylastngames <- function( #' **Get NBA Stats API Team Dashboard by Opponent** -#' @name tbyopponent +#' @name nba_teamdashboardbyopponent NULL #' @title #' **Get NBA Stats API Team Dashboard by Opponent** -#' @rdname tbyopponent +#' @rdname nba_teamdashboardbyopponent #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -486,6 +506,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Dashboard by Opponent](https://www.nba.com/stats/team/1610612749/traditional?Split=opp) +#' ```r +#' nba_teamdashboardbyopponent(team_id = '1610612749', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_teamdashboardbyopponent <- function( date_from = '', date_to = '', @@ -503,7 +528,7 @@ nba_teamdashboardbyopponent <- function( per_mode = 'Totals', period = 0, rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -560,11 +585,11 @@ nba_teamdashboardbyopponent <- function( #' **Get NBA Stats API Team Dashboard by Shooting Splits** -#' @name tbyshootingsplits +#' @name nba_teamdashboardbyshootingsplits NULL #' @title #' **Get NBA Stats API Team Dashboard by Shooting Splits** -#' @rdname tbyshootingsplits +#' @rdname nba_teamdashboardbyshootingsplits #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -597,6 +622,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Dashboard by Shooting Splits](https://www.nba.com/stats/team/1610612749/shooting) +#' ```r +#' nba_teamdashboardbyshootingsplits(team_id = '1610612749', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_teamdashboardbyshootingsplits <- function( date_from = '', date_to = '', @@ -614,7 +644,7 @@ nba_teamdashboardbyshootingsplits <- function( per_mode = 'Totals', period = 0, rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -672,11 +702,11 @@ nba_teamdashboardbyshootingsplits <- function( #' **Get NBA Stats API Team Dashboard by Team Performance** -#' @name tbyteamperformance +#' @name nba_teamdashboardbyteamperformance NULL #' @title #' **Get NBA Stats API Team Dashboard by Team Performance** -#' @rdname tbyteamperformance +#' @rdname nba_teamdashboardbyteamperformance #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -708,6 +738,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Dashboard by Team Performance](https://www.nba.com/stats/team/1610612749/traditional?Split=teamperf) +#' ```r +#' nba_teamdashboardbyteamperformance(team_id = '1610612749', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_teamdashboardbyteamperformance <- function( date_from = '', date_to = '', @@ -725,7 +760,7 @@ nba_teamdashboardbyteamperformance <- function( per_mode = 'Totals', period = 0, rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -782,11 +817,11 @@ nba_teamdashboardbyteamperformance <- function( #' **Get NBA Stats API Team Dashboard Year over Year** -#' @name tbyyearoveryear +#' @name nba_teamdashboardbyyearoveryear NULL #' @title #' **Get NBA Stats API Team Dashboard Year over Year** -#' @rdname tbyyearoveryear +#' @rdname nba_teamdashboardbyyearoveryear #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -817,6 +852,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Dashboard by Year over Year](https://www.nba.com/stats/team/1610612749/traditional?Split=yoy) +#' ```r +#' nba_teamdashboardbyyearoveryear(team_id = '1610612749', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_teamdashboardbyyearoveryear <- function( date_from = '', date_to = '', @@ -834,7 +874,7 @@ nba_teamdashboardbyyearoveryear <- function( per_mode = 'Totals', period = 0, rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -891,11 +931,11 @@ nba_teamdashboardbyyearoveryear <- function( #' **Get NBA Stats API Team Dashboard - Lineups** -#' @name teamdashlineups +#' @name nba_teamdashlineups NULL #' @title #' **Get NBA Stats API Team Dashboard - Lineups** -#' @rdname teamdashlineups +#' @rdname nba_teamdashlineups #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -928,6 +968,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Lineups Dashboard](https://www.nba.com/stats/team/1610612749/lineups-traditional) +#' ```r +#' nba_teamdashlineups(team_id = '1610612749', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_teamdashlineups <- function( date_from = '', date_to = '', @@ -947,7 +992,7 @@ nba_teamdashlineups <- function( per_mode = 'Totals', period = 0, rank = 'N', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', shot_clock_range = '', @@ -1007,11 +1052,11 @@ nba_teamdashlineups <- function( #' **Get NBA Stats API Team Dashboard Player Tracking - Passing** -#' @name t_ptpass +#' @name nba_teamdashptpass NULL #' @title #' **Get NBA Stats API Team Dashboard Player Tracking - Passing** -#' @rdname t_ptpass +#' @rdname nba_teamdashptpass #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -1034,6 +1079,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Player Tracking (Second Spectrum) Stats - Passing](https://www.nba.com/stats/team/1610612749/passes-dash) +#' ```r +#' nba_teamdashptpass(team_id = '1610612749', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_teamdashptpass <- function( date_from = '', date_to = '', @@ -1044,7 +1094,7 @@ nba_teamdashptpass <- function( opponent_team_id = 0, outcome = '', per_mode = 'Totals', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '1610612749', @@ -1093,11 +1143,11 @@ nba_teamdashptpass <- function( #' **Get NBA Stats API Team Dashboard Player Tracking - Rebounding** -#' @name t_ptreb +#' @name nba_teamdashptreb NULL #' @title #' **Get NBA Stats API Team Dashboard Player Tracking - Rebounding** -#' @rdname t_ptreb +#' @rdname nba_teamdashptreb #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -1123,6 +1173,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Player Tracking (Second Spectrum) Stats - Rebounds](https://www.nba.com/stats/team/1610612749/rebounds-dash) +#' ```r +#' nba_teamdashptreb(team_id = '1610612749', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_teamdashptreb <- function( date_from = '', date_to = '', @@ -1135,7 +1190,7 @@ nba_teamdashptreb <- function( outcome = '', per_mode = 'Totals', period = 0, - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '1610612749', @@ -1186,11 +1241,11 @@ nba_teamdashptreb <- function( } #' **Get NBA Stats API Team Dashboard Player Tracking - Shots** -#' @name t_ptshots +#' @name nba_teamdashptshots NULL #' @title #' **Get NBA Stats API Team Dashboard Player Tracking - Shots** -#' @rdname t_ptshots +#' @rdname nba_teamdashptshots #' @author Saiem Gilani #' @param date_from date_from #' @param date_to date_to @@ -1217,6 +1272,11 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' [Team Player Tracking (Second Spectrum) Stats - Shooting](https://www.nba.com/stats/team/1610612749/shots-dash) +#' ```r +#' nba_teamdashptshots(team_id = '1610612749', season = year_to_season(most_recent_nba_season() - 1)) +#' ``` nba_teamdashptshots <- function( date_from = '', date_to = '', @@ -1229,7 +1289,7 @@ nba_teamdashptshots <- function( outcome = '', per_mode = 'Totals', period = 0, - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', team_id = '1610612749', diff --git a/R/nba_stats_video.R b/R/nba_stats_video.R index c5f8e10a..0f1281fd 100644 --- a/R/nba_stats_video.R +++ b/R/nba_stats_video.R @@ -1,9 +1,9 @@ #' **Get NBA Stats API Video Details** -#' @name nba_stats_videodetails +#' @name nba_videodetailsasset NULL #' @title #' **Get NBA Stats API Video Details** -#' @rdname nba_stats_videodetails +#' @rdname nba_videodetailsasset #' @author Saiem Gilani #' @param ahead_behind ahead_behind #' @param clutch_time clutch_time @@ -36,11 +36,155 @@ NULL #' @param vs_conference vs_conference #' @param vs_division vs_division #' @param ... Additional arguments passed to an underlying function like httr. -#' @return Return a list of tibbles +#' @return Return a list of tibbles: videoUrls, playlist #' @importFrom jsonlite fromJSON toJSON #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_videodetailsasset(player_id = '2544', team_id = '1610612747') +#' ``` +nba_videodetailsasset <- function( + ahead_behind = '', + clutch_time = '', + context_filter = '', + context_measure = 'FGA', + date_from = '', + date_to = '', + end_period = '', + end_range = '', + game_id = '', + game_segment = '', + last_n_games = 0, + league_id = '00', + location = '', + month = 0, + opponent_team_id = 0, + outcome = '', + period = 0, + player_id = '2544', + point_diff = '', + position = '', + range_type = '', + rookie_year = '', + season = year_to_season(most_recent_nba_season() - 1), + season_segment = '', + season_type = 'Regular Season', + start_period = '', + start_range='', + team_id = '1610612747', + vs_conference = '', + vs_division = '', + ...){ + season_type <- gsub(' ','+',season_type) + version <- "videodetailsasset" + endpoint <- nba_endpoint(version) + + full_url <- paste0(endpoint, + "?AheadBehind=", ahead_behind, + "&ClutchTime=", clutch_time, + "&ContextFilter=", context_filter, + "&ContextMeasure=", context_measure, + "&DateFrom=", date_from, + "&DateTo=", date_to, + "&EndPeriod=", end_period, + "&EndRange=", end_range, + "&GameID=", game_id, + "&GameSegment=", game_segment, + "&LastNGames=", last_n_games, + "&LeagueID=", league_id, + "&Location=", location, + "&Month=", month, + "&OpponentTeamID=", opponent_team_id, + "&Outcome=", outcome, + "&Period=", period, + "&PlayerID=", player_id, + "&PointDiff=", point_diff, + "&Position=", position, + "&RangeType=", range_type, + "&RookieYear=", rookie_year, + "&Season=", season, + "&SeasonSegment=", season_segment, + "&SeasonType=", season_type, + "&StartPeriod=", start_period, + "&StartRange=", start_range, + "&TeamID=", team_id, + "&VsConference=", vs_conference, + "&VsDivision=", vs_division) + tryCatch( + expr = { + + resp <- request_with_proxy(url = full_url, ...) + videoUrls <- resp$resultSets$Meta$videoUrls %>% + data.frame() %>% + dplyr::as_tibble() + playlist <- resp$resultSets$playlist %>% + data.frame() %>% + dplyr::as_tibble() + df_list <- c(list(videoUrls), list(playlist)) + names(df_list) <- c("videoUrls", "playlist") + + }, + error = function(e) { + message(glue::glue("{Sys.time()}: Invalid arguments or no video detail assets data available!")) + }, + warning = function(w) { + }, + finally = { + } + ) + return(df_list) +} + + +#' **Get NBA Stats API Video Details** +#' @name nba_videodetails +NULL +#' @title +#' **Get NBA Stats API Video Details** +#' @rdname nba_videodetails +#' @author Saiem Gilani +#' @param ahead_behind ahead_behind +#' @param clutch_time clutch_time +#' @param context_filter context_filter +#' @param context_measure context_measure +#' @param date_from date_from +#' @param date_to date_to +#' @param end_period end_period +#' @param end_range end_range +#' @param game_id game_id +#' @param game_segment game_segment +#' @param last_n_games last_n_games +#' @param league_id league_id +#' @param location location +#' @param month month +#' @param opponent_team_id opponent_team_id +#' @param outcome outcome +#' @param period period +#' @param player_id player_id +#' @param point_diff point_diff +#' @param position position +#' @param range_type range_type +#' @param rookie_year rookie_year +#' @param season season +#' @param season_segment season_segment +#' @param season_type season_type +#' @param start_period start_period +#' @param start_range start_range +#' @param team_id team_id +#' @param vs_conference vs_conference +#' @param vs_division vs_division +#' @param ... Additional arguments passed to an underlying function like httr. +#' @return Return a list of tibbles: videoUrls, playlist +#' @importFrom jsonlite fromJSON toJSON +#' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble +#' @import rvest +#' @export +#' @details +#' ```r +#' nba_videodetails(player_id = '2544', team_id = '1610612747') +#' ``` nba_videodetails <- function( ahead_behind = '', clutch_time = '', @@ -64,12 +208,12 @@ nba_videodetails <- function( position = '', range_type = '', rookie_year = '', - season = '2020-21', + season = year_to_season(most_recent_nba_season() - 1), season_segment = '', season_type = 'Regular Season', start_period = '', start_range='', - team_id = '1610612739', + team_id = '1610612747', vs_conference = '', vs_division = '', ...){ @@ -112,8 +256,14 @@ nba_videodetails <- function( expr = { resp <- request_with_proxy(url = full_url, ...) - - df_list <- nba_stats_map_result_sets(resp) + videoUrls <- resp$resultSets$Meta$videoUrls %>% + data.frame() %>% + dplyr::as_tibble() + playlist <- resp$resultSets$playlist %>% + data.frame() %>% + dplyr::as_tibble() + df_list <- c(list(videoUrls), list(playlist)) + names(df_list) <- c("videoUrls", "playlist") }, error = function(e) { @@ -129,20 +279,24 @@ nba_videodetails <- function( #' **Get NBA Stats API Video Events** -#' @name nba_stats_videoevents +#' @name nba_videoevents NULL #' @title #' **Get NBA Stats API Video Events** -#' @rdname nba_stats_videoevents +#' @rdname nba_videoevents #' @author Saiem Gilani #' @param game_id game_id #' @param game_event_id game_event_id #' @param ... Additional arguments passed to an underlying function like httr. -#' @return Return a list of tibbles +#' @return Return a list of tibbles: videoUrls, playlist #' @importFrom jsonlite fromJSON toJSON #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_videoevents(game_id = '0021700807', game_event_id = '0') +#' ``` nba_videoevents <- function( game_id = '0021700807', game_event_id = '0', @@ -159,7 +313,15 @@ nba_videoevents <- function( resp <- request_with_proxy(url = full_url, ...) - df_list <- nba_stats_map_result_sets(resp) + videoUrls <- resp$resultSets$Meta$videoUrls %>% + data.frame() %>% + dplyr::as_tibble() + playlist <- resp$resultSets$playlist %>% + data.frame() %>% + dplyr::as_tibble() + + df_list <- c(list(videoUrls), list(playlist)) + names(df_list) <- c("videoUrls", "playlist") }, error = function(e) { @@ -174,12 +336,12 @@ nba_videoevents <- function( } -#' **Get NBA Stats API Video Events** -#' @name nba_stats_videoevents +#' **Get NBA Stats API Video Status** +#' @name nba_videostatus NULL #' @title -#' **Get NBA Stats API Video Events** -#' @rdname nba_stats_videoevents +#' **Get NBA Stats API Video Status** +#' @rdname nba_videostatus #' @author Saiem Gilani #' @param game_date game_date #' @param league_id league_id @@ -189,6 +351,10 @@ NULL #' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble #' @import rvest #' @export +#' @details +#' ```r +#' nba_videostatus(game_date = '2023-03-10', league_id = '00') +#' ``` nba_videostatus <- function( game_date = '2023-03-10', league_id = '00', diff --git a/R/utils_nba_stats.R b/R/utils_nba_stats.R index 474ff6e3..aa0926dd 100644 --- a/R/utils_nba_stats.R +++ b/R/utils_nba_stats.R @@ -99,6 +99,10 @@ request_with_proxy <- function(url, return(headers) } +nba_live_endpoint <- function(endpoint){ + base_url = glue::glue('https://cdn.nba.com/static/json/liveData/{endpoint}') + return(base_url) +} nba_endpoint <- function(endpoint){ all_endpoints = c( 'alltimeleadersgrids', @@ -240,6 +244,34 @@ nba_endpoint <- function(endpoint){ } +nba_stats_map_result_sets <- function(resp) { + if ("resultSets" %in% names(resp)) { + df_list <- purrr::map(1:length(resp$resultSets$name), function(x){ + data <- resp$resultSets$rowSet[[x]] %>% + data.frame(stringsAsFactors = F) %>% + dplyr::as_tibble() + + json_names <- resp$resultSets$headers[[x]] + colnames(data) <- json_names + return(data) + }) + names(df_list) <- resp$resultSets$name + return(df_list) + } else { + df_list <- purrr::map(1:length(resp$resultSet$name), function(x){ + data <- resp$resultSet$rowSet[[x]] %>% + data.frame(stringsAsFactors = F) %>% + dplyr::as_tibble() + + json_names <- resp$resultSet$headers[[x]] + colnames(data) <- json_names + return(data) + }) + names(df_list) <- resp$resultSet$name + return(df_list) + } +} + pad_id <- function(id = 21601112) { zeros <- 10 - nchar(id) @@ -266,19 +298,7 @@ pad_time <- function(time = 1) { glue("{start}{time}") %>% as.character() } -nba_stats_map_result_sets <- function(resp) { - df_list <- purrr::map(1:length(resp$resultSets$name), function(x){ - data <- resp$resultSets$rowSet[[x]] %>% - data.frame(stringsAsFactors = F) %>% - dplyr::as_tibble() - json_names <- resp$resultSets$headers[[x]] - colnames(data) <- json_names - return(data) - }) - names(df_list) <- resp$resultSets$name - return(df_list) -} #' @title **year to season (XXXX -> XXXX-YY)** #' @param year Four digit year (XXXX) #' @importFrom dplyr mutate filter select left_join diff --git a/cran-comments.md b/cran-comments.md index b0ec5ec8..999ccad1 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -5,6 +5,11 @@ This is a minor release that adds the following: * ```espn_mbb_game_rosters()``` function added. * ```espn_nba_game_rosters()``` function added. * ```nba_shotchartlineupdetail()``` function added. + * ```nba_synergyplaytypes()``` function added. + * ```nba_live_pbp()``` function added. + * ```nba_live_boxscore()``` function added. + * ```nba_franchiseleaderswrank()``` function added. + * ```nba_videodetailsasset()``` function added. diff --git a/man/alltime.Rd b/man/nba_alltimeleadersgrids.Rd similarity index 86% rename from man/alltime.Rd rename to man/nba_alltimeleadersgrids.Rd index d6bdab2f..52013f28 100644 --- a/man/alltime.Rd +++ b/man/nba_alltimeleadersgrids.Rd @@ -1,7 +1,6 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/nba_stats_leaders.R -\name{alltime} -\alias{alltime} +\name{nba_alltimeleadersgrids} \alias{nba_alltimeleadersgrids} \title{\strong{Get NBA Stats API All-time Leaders Grid}} \usage{ @@ -33,6 +32,10 @@ FG_PCTLeaders, FTALeaders, FTMLeaders, FT_PCTLeaders, GPLeaders, OREBLeaders, PF \strong{Get NBA Stats API All-time Leaders Grid} } +\details{ +\if{html}{\out{