devtools install_github vs Cloning GitHub Repositories Explained

Author

Reads 784

Close Up Photo of Programming of Codes
Credit: pexels.com, Close Up Photo of Programming of Codes

If you're working with R and GitHub, you've probably come across the terms `install_github` and cloning a repository. Cloning a repository is a manual process where you download a copy of the repository to your local machine, whereas `install_github` is a function in the `devtools` package that automates this process.

`install_github` is a convenient way to get started with a new package or repository, as it saves you the trouble of manually cloning the repository and installing the package.

The `install_github` function takes the repository owner and repository name as arguments, and it will download the repository and install the package for you.

This process is much faster than cloning a repository manually, especially for larger repositories.

Arguments

When installing packages from GitHub, you'll need to specify the repository address. This can be done in the format of username/repo[/subdir][@ref|#pull|@*release], or you can use the respective parameters subdir and/or ref. If both are specified, the values in repo take precedence.

Two professionals collaborating on software development in a modern indoor setting.
Credit: pexels.com, Two professionals collaborating on software development in a modern indoor setting.

You can also use a personal access token (PAT) to install from a private repo. This is a safer option than using a password, as you can easily delete a PAT without affecting other accounts.

To install dependencies from a private repo, you'll need to generate a PAT with at least repo scope on the GitHub settings page.

You can override the GitHub API host by specifying your enterprise hostname, for example, "github.hostname.com/api/v3".

The type of dependencies you want to install can be specified using the dependencies argument. TRUE is shorthand for "Depends", "Imports", "LinkingTo", and "Suggests", while FALSE is shorthand for no dependencies.

Here are the possible values for the dependencies argument:

  • TRUE: "Depends", "Imports", "LinkingTo", and "Suggests"
  • FALSE: no dependencies
  • NA: "Depends", "Imports", and "LinkingTo" (default)
  • soft: same as TRUE
  • hard: same as NA

You can also specify dependencies from additional fields, such as Config/Needs/website or Config/Needs/coverage.

The upgrade argument determines whether to upgrade package dependencies. The possible values are "default", "ask", "always", or "never". "default" respects the value of the R_REMOTES_UPGRADE environment variable if set, and falls back to "ask" if unset.

Devtools vs Cloning GitHub Repositories

Credit: youtube.com, How to Clone a GitHub Repository | Step by Step Tutorial | #githubdesktop

Using devtools::install_github and cloning a GitHub repository may seem like two similar ways to install a package, but they have key differences.

devtools::install_github is an R function that attempts to install a package directly from GitHub repositories. It allows you to install packages automatically from GitHub and even install multiple repositories in a single call.

git clone is a console command that clones a git repository, copying all the files, but you can only clone one repository by command. You may need to build and install the package after cloning it.

If you just want to run or use the package, use remotes::install_github(). If you want to edit or contribute to the source code for a package, then use git clone to get the code.

Updating a Package

Updating a Package is a crucial part of keeping your R environment up-to-date. The install_github function in devtools allows you to install packages from GitHub while also updating dependencies.

If you want to install a package from GitHub, but not update any of the dependencies, you can use the install_github function with the upgrade_dependencies argument set to FALSE.

6.1 Git2r Dependency

Credit: youtube.com, Dependency management using git submodules

If you're having trouble installing devtools, a common culprit is the git2r dependency. It's often the reason you see error messages like "git2r not found" in your installation logs.

You should take a closer look at those logs for any hints about what's going on. If you see something like "git2r not found", it's likely that's your problem.

Try running a command like sudo apt-get libssl-dev or sudo yum install openssl-devel on your Linux machine to see if that resolves the issue. This can often fix the problem and allow devtools to install properly.

Frequently Asked Questions

How to install a package from GitHub?

To install a package from GitHub, authenticate with your package client and follow the client's installation instructions.

Viola Morissette

Assigning Editor

Viola Morissette is a seasoned Assigning Editor with a passion for curating high-quality content. With a keen eye for detail and a knack for identifying emerging trends, she has successfully guided numerous articles to publication. Her expertise spans a wide range of topics, including technology and software tutorials, such as her work on "OneDrive Tutorials," where she expertly assigned and edited pieces that have resonated with readers worldwide.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.