Learn R Programming

⚠️There's a newer version (0.1.110202031) of this package.Take me there.

nbastatR

An interface for professional basketball data in R. Data sources include, but are not limited to: NBA Stats API, Basketball Insiders, Basketball-Reference, HoopsHype, and RealGM. Overtime additional data sources will be added.

This package is in it's extreme infancy but it should work if you have the necassary packages installed. Formal vigentte's will come once the wrappers are complete but you please explore around. Here is some sample code encompassing some of what nbastatR can do. Once the nbastats API is fully wrapped full documentation will come.

Installation

devtools::install_github("abresler/nbastatR")
library("nbastatR") # note requires a bunch of other packages which are listed in the import

Explore A Season with the NBA Stats API

all_nba_players <- 
	get_nba_players_ids(league = "NBA",
											active_only = F)

players_1998 <-
	get_nba_season_players(
		year.season_start = 1998,
		include_only_rostered_players = F,
		return_message = T
	)
brooklyn_nets_2016_roster <- 
  get_nba_team_season_roster(team = "Brooklyn Nets", year_season_end = 2016)

players_1998_2015 <- get_nba_seasons_players(years = 1998:2014,
																						 only_on_roster = T,
																						 message = F)

profiles_2015_season <-
	get_season_player_profiles(year.season_start = 2014, include_headline_stats = T,
														 only_rostered_players = T,
														 message = T)

Other Functionality

get_day_nba_games("02/11/2016")
get_day_nba_game_scores(date = "10/06/15")
get_day_nba_game_team_leaders("02/08/16")
get_nba_franchise_data(return_franchises = "all")
get_nba_team_stat_table(year.season_start = 2015,
                        period = 4,
                        division_against = "Atlantic",
                        outcome = "W")
get_nba_player_injuries(filter_returning_today = T)
get_nba_synergy_stats(table_name = "Isolation",
                      include_defense = T,
                      include_offense = T,
                      type_table = 'player') # Player isolations
get_nba_synergy_stats(table_name = "Transition",
           include_defense = T,
           include_offense = T,
           type_table = "team", #team transition
           return_message = T)
  

NBA Stats Beta NLP API

This function allows you to ask the NBA's new NLP API a question and it will return an answer in a data frame when possible.

ask_nba_api_nlp_question(question = "BROOKLYN NETS WINS ALL TIME",
                         return_similar_questions = T)

ask_nba_api_nlp_question(question = "Most points ever scored in a game",
                         return_similar_questions = T)

ask_nba_api_nlp_question(question = "Rudy Gobert Free Throw Percentage All Time",
                         return_similar_questions = T)

ask_nba_api_nlp_question(question = "Derrick Rose points against LeBron James")
questions <- 
  c('Wayne Ellington catch and shoot field goals', 'Joe Johnson catch and shoot field goals')
questions %>% 
  ask_nba_api_nlp_questions()

NBA Draft Functions

get_year_draft_combine(combine_year = 2009, return_message = T)
get_all_draft_combines(combine_years = 2000:2015) #draft combines
get_all_draft_data(draft_years = 1960:2015) # drafts

Salary Cap Data Example

all_salaries <- 
  get_all_team_salaries()

non_guaranteed_players <- 
  all_salaries %>% 
  dplyr::filter(id.season %in% c("2015-16", "2016-17"),
                is.non.guaranteed == T)

non_guaranteed_players %>% 
  View()

team_2017_non_guaranteed_players <- 
  non_guaranteed_players %>% 
  group_by(id.season, team) %>% 
  summarise(players = n(),
            total.non_guaranteed.salary = sum(value, na.rm = T) %>% formattable::currency(digits = 0)
            ) %>% 
  ungroup() %>% 
  arrange(desc(total.non_guaranteed.salary))

team_2017_non_guaranteed_players %>% 
  View()

Coaching Data Examples

get_bref_coach_transaction_df(coach = "David Blatt")
get_bref_coach_bio_df("Steve Kerr")
get_bref_coach_stat_df("Monty Williams")
get_bref_coach_award_df("Gregg Popovich")

Mock Draft

draft_2016 <- 
  get_nba_draftnet_year_mock_draft(draft_year = 2016)

mocks_09_15 <- 
  get_nba_draftnet_years_mock_draft(draft_years = 2009:2015)

Copy Link

Version

Version

0.1.10131

License

MIT + file LICENSE

Maintainer

Last Published

July 31st, 2021

Functions in nbastatR (0.1.10131)

get_data_draft_express_combine_sources

Draft Express Combine Sources
get_data_draft_express_measurements

Draft Express Measurements
generate_som

Generate SOM
get_agents_player_data_df

Get agents players
get_day_nba_game_player_tracking_availability

Get Day NBA Game Player Tracking Availibility
get_day_nba_game_scores

Title
get_days_nba_league_standings

Get Days NBA League Standings
get_days_nba_matchups

Get Days NBA Matchups
get_all_teams_season_coaches

Get All Teams Season Coaches
get_all_teams_seasons_coaches

Get All Team Seasons Coaches
get_day_nba_teams_last_meeting

Get Day NBA Tams Last Meeting
get_days_nba_game_player_tracking_availability

Get Days NBA Player Tracking Availibility Data
get_nba_franchise_data

get_nba_franchise_data
get_nba_players_ids

Get NBA Player IDs
get_nba_season_players

Title
get_nba_seasons_players

Get NBA Seasons Players
get_shot_pct

get shot pct
get_data_all_nba_teams

All NBA teams
get_data_bref_players_seasons

Basketball Reference Player Season Tables
get_day_nba_game_team_leaders

Get Day NBA Game Team Leaders
get_day_nba_games

Get Day NBA Game
get_headers_combine

get headers combine
get_team_id_df

Get Team ID DF
get_yahoo_team_salary_data

get_yahoo_team_salary_data
get_yahoo_team_url_df

get_yahoo_team_url_df
get_days_nba_game_team_leaders

Get Days NBA Game Team Leaders
get_days_nba_games

Get Days NBA Games
get_fd_name_df

Title
clean_to_stem

Clean to Stem
function_packages

Title
get_days_nba_scores

Get Days NBA Scores
get_days_nba_teams_last_meeting

Get days NBA teams last meeting
get_player_season_gamelog

Title
get_headers

Get Headers DF
get_nba_team_season_coaches

Get NBA Team Season Coaches
get_nba_team_season_roster

Get NBA Team's Season Roster
get_players_season_stat_splits

Get Players Seasons Stat Splits
get_day_nba_league_standings

Get Day NBA League Standings
get_day_nba_matchups

Get Day NBA Matchups
get_player_season_stat_split

Get Player Season Stat Split
get_nba_day_score_json_data

Get Days JSON Score data
get_nba_team_stat_table

get_nba_team_stat_table
get_player_profile

Get Player Profile
get_team_season_shot_data

Get Teams Shot Data
get_team_season_stat_splits

Get Team Season Stat Splits
get_teams_season_stat_splits

Get Teams Seasons Stat Splits
get_teams_yahoo_player_salary_data

get_teams_yahoo_player_salary_data
get_year_draft_combine

Get Year Draft Combines
get_years_draft_combines

get years draft combines
height_in_inches

Height in Inches
parse_yahoo_player_salary_data

parse_yahoo_player_salary_data
get_season_player_profiles

Get Seaons Player Profiles
get_teams_yahoo_team_salary_data

get_teams_yahoo_team_salary_data
get_yahoo_item_name_df

get_yahoo_item_name_df
visualize_topology_network

Plot Topology Network
get_player_season_shot_data

GET NBA PLAYER SHOT DETAIL DATA
get_team_yahoo_player_salary_data

get_team_yahoo_player_salary_data
get_team_yahoo_team_salary_data

get_team_yahoo_player_salary_data
get_players_agents

get players agents
get_yahoo_nba_team_data

get_yahoo_nba_team_data
get_yahoo_roster_salary_data

get_roster_salary_data
plot_nba_team_season_bokeh_shotchart

Gets NBA team Bokeh Shot Chart
visualize_similar_players

Visualize Similar Players
parse_yahoo_team_salary_data

parse_yahoo_team_salary_data
plot_nba_player_bokeh_shotchart

Get's NBA player's season shot chart with specific parameters