Open Hannah-Davies opened 4 months ago
= Installing Packages from GitLab in R =
== Introduction == In R, you can install packages not only from CRAN but also directly from Git repositories, including GitLab. This guide will walk you through the process of installing R packages from GitLab using different methods.
== Prerequisites ==
devtools
package is required for installing packages from Git repositories. Install it if you haven't already:
{{code language="r"}}
install.packages("devtools")
{{/code}}== Installing Packages from GitLab == There are different methods to install packages from GitLab:
=== Using devtools::install_gitlab
===
The devtools
package provides a convenient function install_gitlab
for installing packages directly from a GitLab repository.
==== Basic Installation ====
To install a package from a public GitLab repository, use the following command:
{{code language="r"}}
devtools::install_gitlab("username/repository")
{{/code}}
Replace username
with the GitLab username and repository
with the repository name.
==== Example ====
If you want to install a package named mypackage
from a user named johndoe
, you would run:
{{code language="r"}}
devtools::install_gitlab("johndoe/mypackage")
{{/code}}
=== Using Authentication for Private Repositories === For private repositories, you need to provide authentication details. You can use a personal access token for this purpose.
==== Generate a Personal Access Token ====
Settings
> Access Tokens
.==== Installation with Access Token ====
You can pass the access token as part of the URL. Use the following format:
{{code language="r"}}
devtools::install_gitlab("username/repository", auth_token = "your_access_token")
{{/code}}
Replace your_access_token
with the token you generated.
=== Using remotes::install_gitlab
===
The remotes
package provides a similar function install_gitlab
, which can also be used to install packages from GitLab.
==== Basic Installation ====
First, install the remotes
package if you haven't already:
{{code language="r"}}
install.packages("remotes")
{{/code}}
Then, use the following command to install the package: {{code language="r"}} remotes::install_gitlab("username/repository") {{/code}}
==== Installation with Access Token ==== For private repositories, you can use the access token similarly: {{code language="r"}} remotes::install_gitlab("username/repository", auth_token = "your_access_token") {{/code}}
== Conclusion ==
Installing packages from GitLab in R is straightforward using the devtools
or remotes
packages. By following the steps outlined in this guide, you can easily install both public and private packages from GitLab repositories. Make sure to handle authentication securely, especially when dealing with private repositories.
Update GitHub instructions so it covers installation of packages in gateway.
See response to Help desk ticket: https://jira.hiru.swan.ac.uk/browse/HD-47452