gistr is a light interface to GitHub’s gists for R.

See also:

  • rgithub an R client for the Github API by Carlos Scheidegger
  • git2r an R client for the libgit2 C library by Stefan Widgren
  • gert Simple git client for R by Jeroen Ooms
  • gistfo for turning your untitled RStudio tabs into gists!

Quick start


Stable version from CRAN

Or dev version from GitHub.



There are two ways to authorise gistr to work with your GitHub account:

  • Generate a personal access token (PAT) with the gist scope selected at and record it in the GITHUB_PAT environment variable.
    • To test out this approach, execute this in R: Sys.setenv(GITHUB_PAT = "blahblahblah"), where “blahblahblah” is the PAT you got from GitHub. Then take gistr out for a test drive.
    • If that works, you will probably want to define the GITHUB_PAT environment variable in a file such as ~/.bash_profile or ~/.Renviron.
  • Interactively login into your GitHub account and authorise with OAuth.

Using the PAT is recommended.

Using the gist_auth() function you can authenticate separately first, or if you’re not authenticated, this function will run internally with each function call. If you have a PAT, that will be used, if not, OAuth will be used.


In gistr you can use pipes, introduced perhaps first in R in the package magrittr, to pass outputs from one function to another. If you have used dplyr with pipes you can see the difference, and perhaps the utility, of this workflow over the traditional workflow in R. You can use a non-piping or a piping workflow with gistr. Examples below use a mix of both workflows. Here is an example of a piping workflow (with some explanation):

file <- system.file("examples", "", package = "gistr")
gists(what = "minepublic")[[1]] %>% # List my public gists, and index to get just the 1st one
  add_files(file) %>% # Add a new file to that gist
  update() # update sends a PATCH command to the Gists API to add the file to your gist online

And a non-piping workflow that does the same exact thing:

file <- system.file("examples", "", package = "gistr")
g <- gists(what = "minepublic")[[1]]
g <- add_files(g, file)

Or you could string them all together in one line (but it’s rather difficult to follow what’s going on because you have to read from the inside out)

file <- system.file("examples", "", package = "gistr")
update(add_files(gists(what = "minepublic")[[1]], file))

List gists

Limiting to a few results here to keep it brief

Since a certain date/time

Request different types of gists, one of public, minepublic, mineall, or starred.

Create gist

You can pass in files

Or, wrap gist_create() around some code in your R session/IDE, with just the function name, and a {' at the start and a }' at the end.

knit code from file path, code block, or gist file

knit a local file

knit a code block (knitr code block notation missing, do add that in) (result not shown)

knit a file from a gist, has to get file first (result not shown)

gists('minepublic')[[1]] %>% run() %>% update()

working with images

The GitHub API doesn’t let you upload binary files (e.g., images) via their HTTP API, which we use in gistr. There is a workaround.

If you are using .Rmd or .Rnw files, you can set imgur_inject = TRUE in gistr_create() so that imgur knit options are injected at the top of your file so that images will be uploaded to imgur. Alternatively, you can do this yourself, setting knit options to use imgur.

A file already using imgur

A file NOT already using imgur

Open a gist in your default browser

gists()[[1]] %>% browse()

Opens the gist in your default browser

Example use case

Working with the Mapzen Pelias geocoding API

The API is described at, and is still in alpha they say. The steps: get data, make a gist. The data is returned from Mapzen as geojson, so all we have to do is literally push it up to GitHub gists and we’re done b/c GitHub renders the map.

And here’s that gist

pelias img