如何使用devtools install_github从私人仓库安装R包?

jpm*_*iaz 31 r github devtools

我正在尝试从我的github仓库安装一个示例包: https://github.com/jpmarindiaz/samplepkg

我可以通过R解释器使用以下任何命令公开repo时安装它:

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

但是当git存储库是私有的时,我得到一个错误:

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
Run Code Online (Sandbox Code Playgroud)

当repo是私有的,任何提示时,我还没弄清楚身份验证的工作原理是什么?

Gab*_*abi 32

您是否尝试过设置个人访问令牌(PAT)并将其作为auth_token参数值传递install_github()

?install_github在底部向下看(包devtools版本1.5.0.99).

  • 确保勾选`repo scope`按钮或devtools将无法安装!http://stat545.com/packages05_foofactors-package-02.html (4认同)

Fer*_*oao 23

在以下位置创建访问令牌:https: //github.com/settings/tokens

将其保存(添加)到文件夹上的.Renviron文件getwd()如下所示:如果您的文件夹是存储库,
GITHUBTOKEN=tokenstring
则添加.Renviron.gitignore文件

或者如果相关的话,将系统范围内的令牌字符串添加到此文件中:
file.path(R.home(),"etc", "Renviron.site")

重新启动 R 会话,以自动加载.Renviron和/或Renviron.site文件

检查分支名称并将其传递给ref

devtools::install_github("user/repo",
                         ref = "main",
                         auth_token = Sys.getenv("GITHUBTOKEN")                          
                        )
Run Code Online (Sandbox Code Playgroud)


小智 10

解决此问题的更现代的解决方案是使用 usethis 和凭据包在 R 中设置凭据。

#set config
usethis::use_git_config(user.name = "YourName", user.email = "your@mail.com")

#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")
Run Code Online (Sandbox Code Playgroud)

更多帮助请访问https://happygitwithr.com/common-remote-setups.html#common-remote-setups