To better understand how complex software projects are evolving it can be helpful to evaluate the associated Git repo. In this post I’ll go over how to retrieve a Git repo and perform various analysis on it using R.
All of these exercises were done within an R notebook in RStudio. You can use any IDE you wish.
First, we’ll install the following libraries.
Clone a repo
The first thing we want to do is clone a Git repo onto our local device. This gives us complete control over the repo without needing to worry about impacting anyone. We’ll evaluate the ggplot2 repository, just for fun.
First, define where the repo is located.
Then let’s create a directory into which the repo will be cloned. The tempdir() command is an easy way to set up a temporary directory.
Create the command that will clone the repo to your local machine.
And invoke the command. Note that this might take while, depending on the size of the repo. Don’t freak out, be patient, everything is going to be fine.
When the clone is complete, check that all is well by looking at the git logs. The next line grabs the first three entries of the repo log.
In their raw form, logs are pretty messy. We can tidy them up using the pretty format options available in git:
Now let’s look at the logs once again
Time to explore a little. First we can look at the history of commits.
A tibble will be produced containing the commit history, looking something like this:
Let’s take a look at who is doing most of the work in this repo.
Tidy author names
It’s common in Git repos for the same author to use different names. This usually happens when people log in from different computers. In this case you see that there are three variations of Hadley Wickham, including “hadley,” “hadley wickham” (lower case), and “Hadley Wickham” (upper case). Let’s clean these up.
And now we can visualize the authors using ggplot
We cloned the git repo into a temporary directory. Now we are able to perform certain git commands and understand commits etc. Now we’ll explore the file dirctory. To do that we need to create a tibble out of the file directory. You might remember that our repo is located at the variable clone_dir
We’ll use the fs library to create the first tibble of the directory, with path type and size.
This will create a tibble that contains all the temporary directories. We don’t care about those, so let’s tidy up a bit by getting rid of them. (Note that your path will differ from mine, you should replace the string with the path that was actually created on your machine).
The tibble contains both directories and files. Let’s split the two so we don’t get confused about what kind of data is contained where.
The visualization we’ll use is looking for a column called pathString, so lets create it
Just for fun, let’s also split out all the directories into their own columns.
The visualization engine needs the data to be in node format, so let’s create that
Let’s install the libraries we’ll need. You might need to install the circlepackeR library first. It’s not on CRAN, so grab it from Github instead
Then load the library
Create the visualization
And save it so that you can interact with it.
The file will appear in RStudio under the “files” section.
And there you have it!