Loading Data From GitHub

Quant
Tutorial on pulling data from GitHub
Author

Mike Aguilar

Published

October 14, 2025

How load data from a GitHub repo?

Public vs Private

  • Ensure the repo is public.

  • If the repo is private then you need to authenticate yourself via username and password.

  • For now we will assume the repo is public.

  • How do you know it’s public? Visit the GitHub repo site. If you don’t need to log in when you visit the repo GitHub site, then it’s public.

Finding the URL

  • When you visit a repo there are often many files.
  • If you click on a csv file you will get a preview in your browser.
  • That csv link is for viewing, it’s not for downloading.
  • The trick is to hover over the “Raw” button, right click, and copy the link.
    • The “Raw” button is typically in near the top toolbar beneath the 3 dots
  • Here’s the two links:
    • Naive copy: https://github.com/AguilarMike/marketobservatory/blob/main/data/NationalIncome-Annual-Data.csv
    • Via Raw: https://github.com/AguilarMike/marketobservatory/raw/refs/heads/main/data/NationalIncome-Annual-Data.csv
    • They look alike, but the differences are important for downloading

Downloading

Download via GitHub

  • You could download the file locally, and then load into R
  • Do this by clicking the download button, which is near the “Raw” button

Download via copy / paste

  • For files like CSV you can can copy from the GitHub website
  • Click on the Raw button. Not a right click; a typical left click
  • This opens the data (if it’s a reasonable size)
  • You can then copy the data from the website
  • From there you can paste into Excel and load into R

Downloading via URL

  • This is by far the most elegant and automated approach
  • Step 1: Define the URL
  • Step 2: read the data

For a CSV it looks like this

urlfile <- 'https://github.com/AguilarMike/marketobservatory/raw/refs/heads/main/data/NationalIncome-Quarterly-Data.csv'
data <- read.csv(urlfile)
head(data)
    Date GrossOutput GrossOutput.P GrossOutput.Q IntInputs IntInputs.P
1 1947Q1          NA            NA            NA        NA          NA
2 1947Q2          NA            NA            NA        NA          NA
3 1947Q3          NA            NA            NA        NA          NA
4 1947Q4          NA            NA            NA        NA          NA
5 1948Q1          NA            NA            NA        NA          NA
6 1948Q2          NA            NA            NA        NA          NA
  IntInputs.Q GrossValueAdded OpEx.EmpComp OpEx.EmpComp.WageSalary
1          NA          243164       128920                  118795
2          NA          245968       130718                  121191
3          NA          249585       132712                  123919
4          NA          259745       136808                  128198
5          NA          265742       140319                  131579
6          NA          272567       141984                  133292
  OpEx.EmpComp.Supplements OpEx.ProductionTax OpEx.Subsidies ConsFixedCap
1                    10125              17679            511        28071
2                     9526              17740            417        28706
3                     8793              18031            364        29515
4                     8610              18974            302        30191
5                     8740              18963            384        30615
6                     8692              19665            292        31086
  ConsFixedCapNational NetOpSurplus.Income NetOpSurplus.StatDisc
1                 9036                  NA                  3072
2                 9561                  NA                  2759
3                10059                  NA                  2006
4                10529                  NA                  3623
5                10972                  NA                   672
6                11356                  NA                 -1087
  NetOpSurplus.Transfers NetOpSurplus.Proprietor NetOpSurplus.RentalIncome
1                    524                   36188                      6657
2                    685                   33262                      6768
3                    797                   33893                      6973
4                    854                   34972                      7157
5                    732                   36384                      7319
6                    705                   40231                      7465
  NetOpSurplus.GovtEnt InterestExpense NetOpSurplus.CorpProfit   OpEx
1                   NA            1992                   20571 146088
2                   NA            2223                   23523 148041
3                   NA            2404                   23616 150379
4                   NA            2465                   25003 155480
5                   NA            2352                   28771 158898
6                   NA            2336                   30473 161357
  GrossOpSurplus EBT NetOpSurplus.Output Margin.GrossMargin Margin.EBITDAMargin
1          97076  NA               69005                 NA                  NA
2          97927  NA               69221                 NA                  NA
3          99206  NA               69691                 NA                  NA
4         104265  NA               74074                 NA                  NA
5         106844  NA               76229                 NA                  NA
6         111210  NA               80124                 NA                  NA
  Margin.EBITMargin Margin.EBTMargin
1                NA               NA
2                NA               NA
3                NA               NA
4                NA               NA
5                NA               NA
6                NA               NA

To load an RData file

# Define the URL to the .RData file
urlfile <- "https://github.com/AguilarMike/marketobservatory/raw/refs/heads/main/data/NationalIncome-Quarterly-Data.RData"

# Create a temporary file to store the download
temp <- tempfile(fileext = ".RData")

# Download the file
download.file(urlfile, temp, mode = "wb")

# Load the RData file into the environment
load(temp)

# Optional: list the objects loaded
print(ls())
[1] "data"                               "metadata"                          
[3] "NationalIncome.Quarterly.Data.Long" "NationalIncome.Quarterly.Data.Wide"
[5] "temp"                               "urlfile"