Create an R package that depends on another R package located on GitHub
Asked Answered
A

2

77

I am creating an R package on GitHub, LW1949, that depends on another R package on GitHub, jvamisc. When I try to install LW1949 using

require(devtools)
devtools::install_github("user/LW1949")

I get the message: Skipping 1 packages not available: jvamisc.

How can I point the import(jvamisc) part of the LW1949 package (in NAMESPACE) to Github instead of CRAN to find this dependency?

Surely this question has been asked and answered before, but I was not successful searching for it (perhaps because the search terms are so common - R, package, GitHub, etc.). I did stumble across Travis CI and Packrat, neither of which I've used. No idea if they would help. I would prefer as simple a fix as possible. (Wouldn't we all?)

I'm using R version 3.1.3 for Windows in R Studio Version 0.98.1103.

Ative answered 27/5, 2015 at 21:22 Comment(5)
Similar question just got askend on r-pkg-devel. If you create a drat repo on github, you can apparently specify it in the Additional_repositories field of your DESCRIPTION file.Rina
Hi Jean. Good to see you on SO. The additional facilities option was also needed when there was a mixture of CRAN and BioC packages that were interdependent, but now you get to specify the search list of repos in an option: options("repos") Also see ?setRepositoriesChoosy
You may want to fork the project and link to that in your package though... in case the original user removes / alters it in a way that breaks your package.Annmaria
You can look into the drat package which makes both creating repos and installing from repos easy.Banded
@NealFultz this seems to be only for a R CMD check purpose, see r-ext. I've tried to set it up for gh package on drat importing another gh package on drat and some other on a CRAN. It didn't use Additional_repositories metadata but throw dependencies not available error.Laius
B
51

This question seems to have been answered quite recently, addressed in this issue of the devtools' github repository.


Package developer POV:

  1. do:

    usethis::use_package("jvamisc")
    devtools::document()
    

to add the dependency in the Imports field of your DESCRIPTION file.

  1. manually add a field "Remotes:" in the DESCRIPTION file, specifying where on github R should look for the package:

    #in DESCRIPTION
    Imports: ...,
      jvamisc,
      ...
    Remotes: JVAdams/jvamisc
    

End-user POV:

  1. the end user has to have the latest development version of devtools (or at least the one corresponding to commit #f21ca3516c). You have to somehow 'force him' to update his devtools version (I guess just put this in the installation instructions... Can't think of a better way)

    devtools::install_github(“hadley/devtools”, ref = “f21ca3516c”)
    
  2. Restart the R Session on unload/reload the devtools package.

  3. do the usual install_github:

    require(devtools)
    devtools::install_github("user/LW1949")
    

I guess this functionality will be added sooner or later to the CRAN version of devtools, so there will be no need for the user to fetch the dev version and he would go directly to step 3).


The steps and additional options are detailed in this vignette.

Boman answered 11/9, 2015 at 23:24 Comment(0)
E
25

The actual solution seems to add in your DESCRIPTION file the line

Remotes: hadley/testthat

see the documentation of devtools :

# Git
Remotes: git::https://github.com/hadley/ggplot2.git

# Bitbucket
Remotes: bitbucket::sulab/mygene.r@default, dannavarro/lsr-package

# Bioconductor
Remotes: bioc::3.3/SummarizedExperiment#117513, bioc::release/Biobase

# SVN
Remotes: svn::https://github.com/hadley/stringr

# URL
Remotes: url::https://github.com/hadley/stringr/archive/master.zip

# Local
Remotes: local::/pkgs/testthat

# Gitorious
Remotes: gitorious::r-mpc-package/r-mpc-package
Enrol answered 7/12, 2016 at 12:13 Comment(3)
If I do add them as Imports and Remotes, check() will complain: Packages required but not available. If I remove them from import, it will complain about the Namespace :)Debutant
Do you know if there is a way to include a specific ref of the github repo package instead of using the most up to date release?Keyser
yes, you can use : Remotes: hadley/testthat@commitORtagEnrol

© 2022 - 2024 — McMap. All rights reserved.