Create an R Package That Depends on Another R Package Located on Github

Make CRAN R package suggest GitHub R package

As you found, you can't use Remotes in a CRAN package. What you need to do is to make sure the .tar.gz file for the package you are depending on is available somewhere. Github doesn't do that automatically, because https://github.com/daviddaigithub/BOLTSSIRR isn't set up as a package repository.

The solution is to create your own small repository, and keep copies of non-CRAN packages there. The drat package (available here: https://github.com/eddelbuettel/drat) makes this easy as long as you have a Github account: follow the instructions here: https://github.com/drat-base/drat. In summary:

  1. Fork https://github.com/drat-base/drat into your account, and clone it to your own computer.
  2. Enable Github Pages with the docs/ folder in the main branch.
  3. Install the drat package into R using remotes::install_github("eddelbuettel/drat"). (I assume this version will make it to CRAN eventually; if you use the current CRAN version instructions are slightly more complicated.)
  4. Build the package you want to insert. You need the source version; you might want binaries too, if those are hard for your users to build.
  5. Run options(dratBranch="docs"); drat::insertPackage(...) to insert those files into your repository.
  6. Commit the changes, and push them to Github.
  7. In the package that needs to use this non-CRAN package, add

    Additional_repositories: https://yourname.github.io/drat

    to the DESCRIPTION.

You will be responsible for updating your repository if BOLTSSIRR is updated. This is good because the updates might break yours: after all, it's still in development mode. It's also bad because your users won't automatically get bug fixes.

That's it, if I haven't missed anything!

R Package Dependency in Github via Remotes not working

There was a typo in the name of the dependency package in its DESCRIPTION file.

This does not make the package fail when installing it directly, but it leads devtools not to find it as a dependency.

Include github packages as imports in DESCRIPTION

Trying to get R's package loaders to install from github sounds like a rabbit hole.

Instead, use something like this in your package's .onload() method.

# install these from github, not CRAN:
pkglist <- list(
c(name='ggplus',url='guiastrennec/ggplus'),
c(name='DT',url='rstudio/DT'))

for(pkg in pkglist)
if(!suppressWarnings(suppressPackageStartupMessages(require(pkg['name'],
quietly=TRUE,character.only=TRUE)))){
devtools::install_github(pkg['url'])
suppressPackageStartupMessages( library(pkg['name'],character.only=TRUE))
}

Creating R package - dependencies

You need to have import statements in your Roxygen headers and NAMESPACE file. First, add @import statements to your Roxygen headers (for example, @import httr). If you are using RStudio, you can Ctrl-Shift-D to automatically update the NAMESPACE file.

See http://r-pkgs.had.co.nz/namespace.html

How to make R package recommend a package hosted on GitHub?

From the manual (and quoting source here):

@c DESCRIPTION field Additional_repositories

The @samp{Additional_repositories} field is a comma-separated list of
repository URLs where the packages named in the other fields may be
found. It is currently used by @command{R CMD check} to check that the
packages can be found, at least as source packages (which can be
installed on any platform).

You can add the package to Suggests: and point to additional repositories -- possibly created using drat. There used to a package doing that, and IIRC there is another one doing it now but its name escaped me now.

Edit: Found it! See here in the source DESCRIPTION file of RNeXML -- and note how the line disappears in the posted DESCRIPTION on CRAN. Better still, note how two of the packages in Suggests: are not listed a hyperlinks on CRAN. I thinks those come from the additional repos. And yes, rOpenSci uses drat to manage that.

Edit 2: And just to close the loop, you (easily) use drat to host such an additional repo on GitHub -- the prime use case for drat.

Edit 3: RNeXML has dropped the additional repository, but the github history still has it.

Edit 4: Currently (i.e. on 2020-03-13), the CRAN packages EMC, bcmaps, blkbox, broom.mixed, epikit, grattan, gtsummary, hurricaneexposure, memoise, multinomialeq, noaastormevents, pointblank, provSummarize, provViz, spData, swephR, tashu, taxadb, waveformbildar all list a field Additional_repositories containing a URL pointing to a drat repo.



Related Topics



Leave a reply



Submit