Skip to content

Instantly share code, notes, and snippets.

@nassimhaddad
Last active December 11, 2015 03:48
Show Gist options
  • Save nassimhaddad/4539941 to your computer and use it in GitHub Desktop.
Save nassimhaddad/4539941 to your computer and use it in GitHub Desktop.
downloads a gist to a file
# downloads a gist
# usage: download_gist("4539629", "4539629.R")
#
# see also: source_gist {devtools}
download_gist <- function (entry, destfile, ...)
{
if (is.numeric(entry) || grepl("^[[:digit:]]+$", entry)) {
entry <- paste("https://raw.github.com/gist/", entry,
sep = "")
}
else if (grepl("((^https://)|^)gist.github.com/[[:digit:]]+$",
entry)) {
entry <- paste("https://raw.github.com/gist/", regmatches(entry,
regexpr("[[:digit:]]+$", entry)), sep = "")
}
download.file(entry, destfile, ...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment