Working With GitHub

Nextjournal makes it easy to work with private and public code repositories and data stores. This article will focus on the platform's GitHub integration.

1.
Add and Mount the Repository

Click on Add new content or use the ➕ insert menu and select Import GitHub Repository. The widget will ask for the repository name, which consists solely of the hosting account and the repository name. In this case the account is nextjournal and the repository is repository-demo thus the Repository Name field reads nextjournal/repository-demo. You can also specify the branch or the specific commit SHA.

Under the Runtime Menu, expand Mounts and then press Add mount. Select the repository's name under Source and the Destination will field will be filled with a default.

Mounts in Nextjournal

The repository defaults to a directory off root. In this case, it's /repository-demo:

ls -lah /repository-demo

2.
Load Data From the Repository

Load the tidyverse collection of R packages, which includes two dependencies used in this article, ggplot2 and readr, and then read in data from the mounted GitHub repository.

library(tidyverse)

artists <- read_csv("/repository-demo/artist_data.csv")

3.
Working With the Repository

3.1.
Version Control and References

Copying the file into content addressed storage at /results from the GitHub repository means the information is automatically version controlled and referenceable.

cp /repository-demo/artist_data.csv /results
artist_data.csv

References are powerful and convenient. There are two ways to use them:

  • Copy the file above and paste in the code cell below. This is done by hovering the mouse cursor to the left of the filename and exposing the copy menu.
  • Insert the reference by typing the @ symbol in a code cell and select Reference. Choose artist_data.csv in the subsequent menu.
artists <- read_csv(artist_data.csv↩)

3.2.
Working With Code

Say the repository has some code you would like to run:

cat /repository-demo/birth-distribution.r

One option is to run the code from within the language. This method will vary from language to language.

source('/repository-demo/birth-distribution.r', local = F, echo = T)

Another option is to cut the code from the cat command above and paste it into the language's code cell.

artists <- read_csv("/repository-demo/artist_data.csv")
born <- artists$yearOfBirth
df <- data.frame(born)

ggplot(df, mapping=aes(x = born, y = as.numeric(row.names(df)))) + 
           geom_point(size=2.2, alpha=0.4, shape=15) + 
           labs(x = "Year", y=element_blank(),
                title = "Distribution of Artist's Birth Years at the Tate", 
                subtitle = "From the Museum's Permanent Collection") + 
           theme_bw() +
           theme(axis.text.y = element_blank(),
                 axis.ticks.y = element_blank(),
                 panel.grid.minor=element_blank(),
                 panel.grid.major.y=element_blank())
© 2018 Nextjournal GmbH