user1569339
user1569339

Reputation: 683

Install/importing an R library from cloned repo

I have an R library cloned from a GitHub repo that I would like to modify. However, I've never built and imported a library in R from anything other than CRAN. How do I go about this?

Upvotes: 6

Views: 5240

Answers (3)

stevec
stevec

Reputation: 52738

In case you want to do it all from the command line, try this:

git clone https://github.com/user/repo.git
R -e "install.packages('devtools');devtools::install('path/to/package')"

Just replace path/to/package with the path to your cloned package. Note if you're on Ubuntu, you might have to install these system libraries first.

Upvotes: 0

David Jacques
David Jacques

Reputation: 348

@GregorThomas comment is so important that I feel it needs to be clarified.

After you build your pakacage, you still need to install it. running devtools::build returns the location of the tar.gz file that you need to install. You can therefore assign that to a variable and pass it to devtools::install_local.

The path that you pass to devtools::build should be whichever folder contains the DESCRIPTION file.

Note, if you want to fork/clone a repo and give your version its own name, you can change the Package value in the DESCRIPTION file and this new name is what you pass to library()

install.packages("devtools")
library(devtools)
my_cloned_library_build = devtools::build("~/put/the/package/path/here")
devtools::install_local(my_cloned_library_build)
library(my_cloned_library)

Upvotes: 0

Michael Kirchner
Michael Kirchner

Reputation: 889

If you intend to modify the code before building, then install_github() will not work. You should clone the git repo to a directory on your machine, and then run:

install.packages("devtools")
library(devtools)
build("~/put/the/package/path/here")

If you are using RStudio, you can use the cloned and modified source to create your own package as described here.

Upvotes: 8

Related Questions