Install R Packages From GitLab
The remotes package makes it possible to install packages from different sources – including GitLab.
For the sake of argument, let us assume my GitLab is hosted at https://gitlab.myorg.com and that I want to install an R package whose repository https://gitlab.myorg.com/path/to/package.
This can be done with the command
remotes::install_gitlab("path/to/package", host = "gitlab.myorg.com", dependencies = TRUE)
Authentication
To authenticate against GitLab’s API a personal access token is needed:
Click on your user profile in the upper right corner and select “Settings”.
Choose “Access Tokens” and create a token with “Scopes” read_api
.
The default option in remotes::install_gitlab
is to look for such a token in an environment variable called GITLAB_PAT
.
To make such a variable available in all R sessions it can be saved in the user .Renviron
file.
This file can be accessed directly from R:
file.edit(path.expand(file.path("~", ".Renviron")))
With a token <token>
it is entered in .Renviron
as
GITLAB_PAT=”<token>”
Internal dependencies
This package may also have dependencies that are located on GitLab.
These should be listed in unofficial Remotes
field in the DESCRIPTION
file as explained in this devtools vignette:
Remotes:
gitlab::path/to/package[@tag]
A package along with its dependencies can then be installed with this command:
devtools::install(dependencies = TRUE, host = "https://gitlab.myorg.com")
The dependencies
argument ensures that packages in the Remotes
and Suggests
fields of DESCRIPTION
gets installed as well.