Skip to content

Commit

Permalink
Update espn_wbb_data.R
Browse files Browse the repository at this point in the history
  • Loading branch information
saiemgilani committed Apr 5, 2023
1 parent e0599a2 commit b0caf20
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions R/espn_wbb_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -2976,20 +2976,27 @@ helper_espn_wbb_player_box <- function(resp){

boxScoreSource <- game_json[["header"]][["competitions"]][["boxscoreSource"]]

valid_stats <- players_box_score_df %>%
tidyr::unnest("statistics")

valid_athletes <- is.data.frame(valid_stats[["athletes"]][[1]]) && is.data.frame(valid_stats[["athletes"]][[2]])
# This is checking if [[athletes]][[1]]'s stat rebounds is able to be converted to a numeric value
# without introducing NA's
suppressWarnings(
valid_stats <- players_box_score_df[["statistics"]][[1]][["athletes"]][[1]][["stats"]][[1]] %>%
purrr::pluck(7) %>%
valid_stats <- players_box_score_df[["statistics"]][[1]][["athletes"]][[1]][["stats"]][[1]] %>%
purrr::pluck(7) %>%
as.numeric()
)
if (boxScoreAvailable == TRUE &&
length(players_box_score_df[["statistics"]][[1]][["athletes"]][[1]]) > 1 &&
length(players_box_score_df[["statistics"]][[1]][["athletes"]][[1]][["stats"]][[1]]) > 1 &&
valid_athletes &&
!is.na(valid_stats)) {

players_df <- players_box_score_df %>%
tidyr::unnest("statistics") %>%
tidyr::unnest("athletes")

if (length(players_box_score_df[["statistics"]]) > 1 &&
length(players_df$stats[[1]] > 0)) {

Expand Down

0 comments on commit b0caf20

Please sign in to comment.