Search code examples
rgitlabdevtoolsinstall.packagesrenv

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?


Solution

  • 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")