I am having trouble finding how to import an XLSX from a private Github repo. For CSV the below is working, is there a standard way to do the same with XLSX other than downloading the file to my local machine?
library(httr)
library(xlsx)
github_link <- "https://raw.githubusercontent.com/..."
api_key <- "<secret_token>"
req <- GET(github_link,
add_headers(Authorization = paste("token", api_key, sep = " ")))
# This works
csv_file <- content(req, type = "text/csv")
# How to do this?
xlsx_file <- loadWorkbook(?????)
As your file is on a github private repo, you may need to create your custom wrapper using httr::write_disk to write on disk, in the tempfile, the result of your GET that uses the API key.
If I find a demo file in a github repo, I will provide an exemple.
rio is a useful package that wraps a nice uniform API around lots of I/O utilities covering most any format you'll find. Among other niceties, it will make and delete tempfiles for you automatically, so if you pass it a URL to an Excel file, it will read it with readxl (or openxlsx if you prefer). It also handles file compression very nicely without extra steps.
so you can just do
test <- rio::import('https://github.com/CerebralMastication/Presentations/raw/master/test.xlsx')
test
#> text
#> 1 what
#> 2 fresh
#> 3 hell
#> 4 is
#> 5 this
I don't believe it can handle authentication, though.