Skip to content

Commit

Permalink
add team abbreviation to nba_teams() function
Browse files Browse the repository at this point in the history
  • Loading branch information
saiemgilani committed Apr 3, 2023
1 parent 694e271 commit faa277a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 32 deletions.
76 changes: 46 additions & 30 deletions R/nba_stats_team.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,32 @@ NULL
#' @param ... Additional arguments passed to an underlying function like httr.
#' @return Return a data frame with the following columns:
#'
#' |col_name |types |
#' |:---------------|:---------|
#' |league_id |character |
#' |season_id |character |
#' |team_id |character |
#' |team_city |character |
#' |team_name |character |
#' |team_slug |character |
#' |conference |character |
#' |division |character |
#' |season |character |
#' |team_name_full |character |
#' |espn_team_id |integer |
#' |abbreviation |character |
#' |display_name |character |
#' |mascot |character |
#' |nickname |character |
#' |team |character |
#' |color |character |
#' |alternate_color |character |
#' |logo |character |
#' |logo_dark |character |
#' |logos_href_3 |character |
#' |logos_href_4 |character |
#' |nba_logo_svg |character |
#' |col_name |types |
#' |:-----------------|:---------|
#' |league_id |character |
#' |season_id |character |
#' |team_id |character |
#' |team_city |character |
#' |team_name |character |
#' |team_slug |character |
#' |conference |character |
#' |division |character |
#' |team_abbreviation |character |
#' |team_name_full |character |
#' |season |character |
#' |espn_team_id |integer |
#' |abbreviation |character |
#' |display_name |character |
#' |mascot |character |
#' |nickname |character |
#' |team |character |
#' |color |character |
#' |alternate_color |character |
#' |logo |character |
#' |logo_dark |character |
#' |logos_href_3 |character |
#' |logos_href_4 |character |
#' |nba_logo_svg |character |
#'
#' @importFrom jsonlite fromJSON toJSON
#' @importFrom dplyr filter select rename bind_cols bind_rows as_tibble
Expand All @@ -48,8 +49,22 @@ nba_teams <- function(...){
tryCatch(
expr = {

standings <- nba_leaguestandingsv3(season = year_to_season(most_recent_nba_season() - 1)) %>%
standings <- nba_leaguestandingsv3(season = year_to_season(most_recent_nba_season() - 1), ...) %>%
purrr::pluck("Standings")

league_gamelog <- nba_leaguegamelog(league_id = '00',
season = year_to_season(most_recent_nba_season() - 1), ...) %>%
purrr::pluck("LeagueGameLog") %>%
dplyr::rename("team_name_full" = "TEAM_NAME") %>%
dplyr::select(
"TEAM_ID",
"TEAM_ABBREVIATION",
"team_name_full") %>%
dplyr::distinct()

standings <- standings %>%
dplyr::left_join(league_gamelog, by = c("TeamID" = "TEAM_ID"))

nba_teams <- standings %>%
dplyr::select(dplyr::any_of(c(
"LeagueID",
Expand All @@ -59,11 +74,12 @@ nba_teams <- function(...){
"TeamName",
"TeamSlug",
"Conference",
"Division"))) %>%
"Division",
"TEAM_ABBREVIATION",
"team_name_full"))) %>%
dplyr::mutate(
Season = paste0('', year_to_season(most_recent_nba_season() - 1)),
TeamNameFull = paste(.data$TeamCity, .data$TeamName)) %>%
dplyr::arrange(.data$TeamNameFull)
Season = paste0('', year_to_season(most_recent_nba_season() - 1))) %>%
dplyr::arrange(.data$team_name_full)

espn_nba_teams <- espn_nba_teams() %>%
dplyr::rename("espn_team_id" = "team_id")
Expand Down
3 changes: 2 additions & 1 deletion man/nba_teams.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/testthat/test-nba_teams.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ test_that("NBA Teams", {
"team_abbreviation",
"team_name_full",
"season",
"team_name_full_2",
"espn_team_id",
"abbreviation",
"display_name",
Expand Down

0 comments on commit faa277a

Please sign in to comment.