This document contains all the needed R code to reproduce the results described in the paper A Basketball Big Data Platform for Box Score and Play-by-Play Data (https://doi.org/10.1089/big.2023.0177).
# Firstly, load BAwiR and other packages that will be used in the paper:
library(BAwiR)
library(tidyverse) The following data file is an illustration of the type of play-by-play data available from the Spanish ACB league.
Do some first data processing:
acb_games_2223_sl <- acb_vbc_cz_sl_2223 %>%
filter(period == "1C")
df1 <- do_prepare_data(df0, day_num,
acb_games_2223_sl, acb_games_2223_info,
game_code)# Lineups and sub-lineups:
data_li <- do_lineup(df1, day_num, game_code, "Valencia Basket", FALSE)
data_subli <- do_sub_lineup(data_li, 4)# Timeouts:
df1_to <- do_prepare_data_to(df0, TRUE, acb_games_2223_info, acb_games_2223_coach)
data_to <- do_time_out_success(df1_to, day_num, game_code,
"Casademont Zaragoza_Porfirio Fisac", FALSE)# Periods:
team_sel <- "Valencia Basket" # "Casademont Zaragoza"
period_sel <- "1C" # "4C"
player_sel <- "Webb" # "Mara"
pre_per <- do_preproc_period(acb_vbc_cz_pbp_2223, team_sel, period_sel, acb_vbc_cz_sl_2223)
df2 <- pre_per$df2
df0_inli_team <- pre_per$df0_inli_team
df3 <- do_prepare_data(df2, day_num, df0_inli_team, acb_games_2223_info, game_code)
data_per <- do_stats_per_period(df3, day_num, game_code, team_sel, period_sel, player_sel)
# Clutch time:
data_clutch <- do_clutch_time(df0)
# If no rows, that means that the game did not have clutch time.# Free throw fouls:
data_ft_comm <- do_ft_fouls(df0, "comm")
data_ft_rec <- do_ft_fouls(df0, "rec")
# Offensive fouls:
data_off_comm <- do_offensive_fouls(df0, "comm")
data_off_rec <- do_offensive_fouls(df0, "rec")# Offensive rebounds:
df1_or <- do_prepare_data_or(df0, TRUE, acb_games_2223_info)
data_or <- do_reb_off_success(df1_or, day_num, game_code, "Valencia Basket", FALSE)## R version 4.6.1 (2026-06-24)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 26.04 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so; LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## time zone: Etc/UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] rmarkdown_2.31
##
## loaded via a namespace (and not attached):
## [1] digest_0.6.39 R6_2.6.1 fastmap_1.2.0 xfun_0.60
## [5] maketools_1.3.2 cachem_1.1.0 knitr_1.51 htmltools_0.5.9
## [9] buildtools_1.0.0 lifecycle_1.0.5 cli_3.6.6 sass_0.4.10
## [13] jquerylib_0.1.4 compiler_4.6.1 sys_3.4.3 tools_4.6.1
## [17] evaluate_1.0.5 bslib_0.11.0 yaml_2.3.12 jsonlite_2.0.0
## [21] rlang_1.3.0