Skip to content

Instantly share code, notes, and snippets.

@christophergandrud
Last active March 31, 2020 04:58
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save christophergandrud/4466237 to your computer and use it in GitHub Desktop.
A function for downloading data stored on GitHub in a plain-text format (e.g. CSV, TSV) into R. The function loads the data as a data frame. For more details see: http://christophergandrud.blogspot.com/2013/01/sourcegithubdata-simple-function-for.html.
#####################
# R function for downloading plain-text data from GitHub
# Christopher Gandrud
# 7 January 2013
#####################
# source_GitHubData is directly based on source_url from the Hadley Wickham's devtools package
source_GitHubData <-function(url, sep = ",", header = TRUE)
{
require(httr)
request <- GET(url)
stop_for_status(request)
handle <- textConnection(content(request, as = 'text'))
on.exit(close(handle))
read.table(handle, sep = sep, header = header)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment