'GitHub' 'API'

Minimal client to access the 'GitHub' 'API'.

Linux Build Status Windows Build status CRAN RStudio mirror downloads Coverage Status

Minimalistic client to access GitHub's API v3.





Use the gh() function to access all API endpoints. The endpoints are listed in the documentation.

The first argument of gh() is the endpoint. Note that the leading slash must be included as well. Parameters can be passed as extra arguments. E.g.

my_repos <- gh("/user/repos", type = "public")
vapply(my_repos, "[[", "", "name")
#>  [1] "after"               "argufy"              "ask"                
#>  [4] "baseimports"         "citest"              "clisymbols"         
#>  [7] "cmaker"              "cmark"               "conditions"         
#> [10] "crayon"              "debugme"             "devtools"           
#> [13] "diffobj"             "disposables"         "dotenv"             
#> [16] "elasticsearch-jetty" "falsy"               "fswatch"            
#> [19] "gitty"               "httr"                "httrmock"           
#> [22] "ISA"                 "keypress"            "lintr"              
#> [25] "macBriain"           "maxygen"             "MISO"               
#> [28] "parr"                "parsedate"           "pingr"

The JSON result sent by the API is converted to an R object.

If the end point itself has parameters, these can also be passed as extra arguments:

j_repos <- gh("/users/:username/repos", username = "jeroenooms")
vapply(j_repos, "[[", "", "name")
#>  [1] "apps"               "asantest"           "awk"               
#>  [4] "base64"             "bcrypt"             "blog"              
#>  [7] "brotli"             "cheerio"            "cmark"             
#> [10] "commonmark"         "covr"               "cranlogs"          
#> [13] "curl"               "cyphr"              "daff"              
#> [16] "data"               "data.table.extras"  "devtools"          
#> [19] "DiagrammeR"         "docdbi"             "docplyr"           
#> [22] "docs-travis-ci-com" "dplyr"              "encode"            
#> [25] "evaluate"           "feather"            "fib"               
#> [28] "figures"            "gdtools"            "geojson"

POST, PATCH, PUT and DELETE requests

POST, PATCH, PUT, and DELETE requests can be sent by including the HTTP verb before the endpoint, in the first argument. E.g. to create a repository:

new_repo <- gh("POST /user/repos", name = "my-new-repo-for-gh-testing")

and then delete it:

gh("DELETE /repos/:owner/:repo", owner = "gaborcsardi",
   repo = "my-new-repo-for-gh-testing")


By default the GITHUB_PAT environment variable is used. Alternatively, one can set the .token argument of gh().


Supply the page parameter to get subsequent pages:

my_repos2 <- gh("GET /users/:username/repos", username = "gaborcsardi",
  type = "public", page = 2)
vapply(my_repos2, "[[", "", "name")
#>  [1] "pkgconfig"               "playground"             
#>  [3] "praise"                  "prettycode"             
#>  [5] "prettyunits"             "progress"               
#>  [7] "prompt"                  "r-font"                 
#>  [9] "R6"                      "rcorpora"               
#> [11] "readline"                "remoji"                 
#> [13] "resume"                  "rhub-presentations"     
#> [15] "rintrojs"                "roxygen"                
#> [17] "scidb"                   "spark"                  
#> [19] "sparklyr"                "splicing"               
#> [21] "tamper"                  "testthat"               
#> [23] "trump"                   "user2016-tutorial-shiny"
#> [25] "webdriver"               "whoami"


MIT © Gábor Csárdi, Jennifer Bryan, Hadley Wickham



First public release.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


1.3.0 by Gábor Csárdi, 9 months ago

https://gh.r-lib.org/, https://github.com/r-lib/gh#readme

Report a bug at https://github.com/r-lib/gh/issues

Browse source code at https://github.com/cran/gh

Authors: Gábor Csárdi [cre, ctb] , Jennifer Bryan [aut] , Hadley Wickham [aut] , RStudio [cph, fnd]

Documentation:   PDF Manual  

Task views: Web Technologies and Services

MIT + file LICENSE license

Imports cli, gitcreds, httr, ini, jsonlite

Suggests covr, knitr, mockery, rmarkdown, rprojroot, spelling, testthat, withr

Imported by codemetar, contribution, devtoolbox, ghclass, ghee, mdapack, natmanager, piggyback, projmgr, rcompendium, stickr, usethis.

Suggested by FishPhyloMaker, RSQLite, circle, desc, devtools.

See at CRAN