Reproducible Circular NBA Barcharts

2/6/2022 3-minute read

These are the steps I took to re-create NBA Circular Barcharts, but in a structured reproducible manner with a Makefile, and Dockerfile. You can find the completed version of this project here.

00_ From the beginning

via GIPHY

00_00_ Folders

Open up a bash terminal and type in the following lines of code:

Terminal Command Description
mkdir nba_proj make nba_proj folder
cd nba_proj move into nba_proj folder
pwd print working directory
mkdir 00_R make 00_R folder for the code
mkdir 01_raw_data make 01_raw_data folder for the raw (scraped) data
mkdir 02_clean_data make 02_clean_data folder for the clean data
mkdir 03_figs make 03_figs folder for the barchart imgs
mkdir 04_output make 04_output folder for report that is printed
mkdir 05_sandbox make 05_sandbox folder as a space to play with the code

Note: I numbered my folders so they would be in the general order I would use them / would want a collaborator to view them.

00_01_ renv

Terminal Command Description
R open R within the terminal
ren::init() creates renv folder and contents
q() quit R
y yes, to save workspace image

Note: Link on how to download and install R through the terminal if not already downloaded to your machine.

00_02_ github

From your github account create a repository nba_proj.

Terminal Command Description
git init initialize git repository
git remote add origin https://github.com/rbolt13/nba_proj.git add location of repository
git status check status
git add * select all
git status check status
git add .Rhistory .Rprofile add dot files that were missed
git status check status
git commit -m “my first commit” adds comment to first commit
git push origin main push to github

Rename master branch to main

01_ project_files.R, Makefile, and report.Rmd

via GIPHY

01_00_ scrape files

Create the following files:

Set environmental variable:

Terminal Command Description
export which_team=“blazers” create global variable
R open R
Sys.getenv(“which_team”) verify that which_team = “blazers”
q() quit R
y yes

Create lines 1-7 of the Makefile, and save the raw data for stats and colors.

Terminal Command Description
make raw_data stats creates stats data file in raw data folder
make raw_data/colors creates colors data file in raw data folder

Push files to github.

01_02_ label data

Create the following file:

Add lines 9-10 of the Makefile, and save the label data.
Terminal Command Description
make raw_data/labels creates labels data file in raw data folder

Push files to github.

01_03_ clean data

Create the following file:

Set environmental variable:

Terminal Command Description
export which_stat=“PTS” create global variable
R open R
Sys.getenv(“which_stat”) verify that which_stat = “PTS”
q() quit R
y yes

Add lines 13-14 of the Makefile, and save the clean data.

Terminal Command Description
make clean_data/raw_data make clean data out of raw data

Push files to github.

01_05_ report

Create the following file:

Add lines 22 - 23 of the Makefile, and save report to output file.

Terminal Command Description
report save report to output folder

Push files to github.

01_06_ env (package management)

Add lines 26 - 27 of the Makefile, and update project.

Terminal Command Description
restore opens R and restores packages

Push files to github.

02_ Dockerfile

via GIPHY

Open docker on your computer.

Terminal Command Description
docker build -t nba_proj . build docker
docker run -it nba_proj /bin/bash run docker interactive nba_proj docker with bash terminal

To be continued…

Bonus Notes

  • Makefile uses tabs not spaces, and you will get an error about missing separator.

  • git add –all