6

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?

user1569339
  • 683
  • 8
  • 20
  • 1
    While I was able to get a solution from the answers and comments below, I will just leave a quick summary here: `devtools::install('path_to_the_cloned_repo/')` -- that's it. – Ufos Feb 09 '18 at 09:42

3 Answers3

8

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.

Michael Kirchner
  • 869
  • 1
  • 7
  • 17
0

@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)
David Jacques
  • 179
  • 2
  • 9
0

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.

stevec
  • 41,291
  • 27
  • 223
  • 311