I used devtools::install_github...
in R to install a repository and also installed the repository by using git clone
in terminal. What's the difference between these two routes? So far, I understand that I can then use library(package)
in R and will load the package in, whereas when I've cloned the GitHub repository, I don't think the package is immediately available. Can anyone explain the difference between these two methods?
Thanks!
CodePudding user response:
git clone
is a general way to check out a local copy of any git repository. It doesn't know about R at all or how R packages work. The devtools::install_github()
(which is really just remotes::install_github()
) checks out a copy of a repository and then does the extra work of actually building and installing the package so R can use it. Also it removes the local copy of the raw source files after it installs. If you just want to run/use the package, use remotes::install_github()
. If you want to edit/contribute to the source code for a package, then use git clone
to get the code.
CodePudding user response:
devtools::install_github
is an R function that attempts to install a package directly from GitHub repositories (Link to Documentation). This allows to install packages automatically from GitHub. You can specify multiple repositories in a single call to the function like this (Example from the previous link that attempts to install multiple repositories):
install_github(c("rstudio/httpuv", "rstudio/shiny"))
git clone
is a console command that clones a git repository, by copying all the files (Link to Documentation). You only can clone one repository by command, and you may need to build and install the package after cloning it. Also, you can clone from hosts different to GitHub, like BitBucket, GitLab, or a custom git server. You can clone a repository like this (Example from the previous link that attempts to clone a repository from a host different to GitHub):
git clone git://git.kernel.org/pub/scm/.../linux.git my-linux