How to install R package from private repo using devtools install_github?

RGithubDevtools

R Problem Overview


I am trying to install a sample package from my github repo: https://github.com/jpmarindiaz/samplepkg

I can install it when the repo is public using any of the following commands through the R interpreter:

  • install_github("jpmarindiaz/rdali")
  • install_github("rdali",user="jpmarindiaz")
  • install_github("jpmarindiaz/rdali",auth_user="jpmarindiaz")

But when the git repository is private I get an Error:

Installing github repo samplepkg/master from jpmarindiaz
Downloading samplepkg.zip from     
https://github.com/jpmarindiaz/samplepkg/archive/master.zip
Error: client error: (406) Not Acceptable

I haven't figured out how the authentication works when the repo is private, any hints?

R Solutions


Solution 1 - R

Have you tried setting a personal access token (PAT) and passing it along as the value of the auth_token argument of install_github()?

See ?install_github way down at the bottom (Package devtools version 1.5.0.99).

Solution 2 - R

Create an access token in: https://github.com/settings/tokens

Check if your repo has a master branch, otherwise use main

devtools::install_github("user/repo"
                         ,ref="main"
                         ,auth_token = "tokenstring"
                         )

Solution 3 - R

A more modern solution to this problem is to set your credentials in R using the usethis and credentials packages.

#set config
usethis::use_git_config(user.name = "YourName", user.email = "[email protected]")

#Go to github page to generate token
usethis::create_github_token() 

#paste your PAT into pop-up that follows...
credentials::set_github_pat()

#now remotes::install_github() will work
remotes::install_github("username/privaterepo")

More help at https://happygitwithr.com/common-remote-setups.html#common-remote-setups

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjpmarindiazView Question on Stackoverflow
Solution 1 - RGabiView Answer on Stackoverflow
Solution 2 - RFerroaoView Answer on Stackoverflow
Solution 3 - RBrandon RoseView Answer on Stackoverflow