Installing non-public packages from Gitlab using devtools::install_git

大城市里の小女人 提交于 2019-11-28 04:41:25

You could try a combination of the devtools and getPass packages.

https://github.com/wrathematics/getPass

devtools::install_git(
  "https://gitlab.com/foo/bar.git", 
  credentials = git2r::cred_user_pass("uname", getPass::getPass())
)

Where uname is your Gitlab user name.

I'd highly recommend going the SSH route, and the below works for that. I found making the leap to SSH was easy, especially with R and RStudio. I'm using Windows in the below example. Edits from code I use in practice are in all caps.

creds = git2r::cred_ssh_key("C:\\Users\\MYSELF\\.ssh\\id_rsa.pub",
                            "C:\\Users\\MYSELF\\.ssh\\id_rsa")
devtools::install_git("git@gitlab.WORKDOMAIN.com:GITLABGROUP/PACKAGE.git",
                      credentials = creds)

Two quick additional comments:

  • git2r is imported with devtools, you shouldn't need to install it separately.
  • Also I don't think this should need mentioning, but passwords in plaintext in your script is a very bad idea.

Per Ciro's comment, authenticating using

https://user:password@domain.com/user/repo.git

does the trick. So the complete call would be

devtools::install_git('https://user:password@mini-me2.lerner.ccf.org/nutterb/modeltable.git')

Please note that there may be security concerns with passing the user name and password this way. I'm not completely educated on those concerns. This works well enough for my purposes because I am authenticated on my company's network to even see the GitLab server.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!