Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use renv for private GitLab package

I have a local GitLab account with an R package that can be installed by:

devtools::install_git( 
  url = "http://my-gitlab/my-projects/package",
  credentials = git2r::cred_user_pass("user", "pass")
)

When I run renv::init() the package source is unknown. The getting started article does give details about how to setup functions to deal with private repos but I can't figure it out for GitLab when using devtools and git2r::cred_user_pass. I could store GIT_USER and GIT_PASSWORD in an .Renviron file but I'm not sure how to force the init function to user devtools::install_git with those credentials. I did try but then I get an error:

fatal: could not read Username for 'http://my-gitlab': No such device or address

All the example options they provide use a GitLab token for authentication:

# use a named list directly
options(renv.auth = list(
  MyPackage = list(GITHUB_PAT = "<pat>")
))

Perhaps there is a better way to install from a local GitLab repo that will work better with renv?

like image 950
Pete900 Avatar asked Sep 02 '26 23:09

Pete900


1 Answers

For anyone else having the same problem, this worked for me (see here):

  • Create a PAT in GITLAB making sure to set the SCOPE to api. Note: I'm not sure this has to be 'api' I didn't check all options but it worked for me
  • Set the PAT as a env variable using Sys.setenv(GITLAB_PAT = <...>)
  • Set the gitlab host server as an option using options(renv.config.gitlab.host = "http://my-gitlab-server"). Note: I had to include "http://" to get it working.
  • Run renv::install("gitlab::project/package")
  • This did not work for me: renv::install("gitlab@my-gitlab-server::project/package")
like image 107
Pete900 Avatar answered Sep 04 '26 11:09

Pete900



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!