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:
- Fork https://github.com/drat-base/drat into your account, and clone it to your own computer.
- Enable Github Pages with the
docs/
folder in the main branch. - Install the
drat
package into R usingremotes::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.) - 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.
- Run
options(dratBranch="docs"); drat::insertPackage(...)
to insert those files into your repository. - Commit the changes, and push them to Github.
- 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
R: Extracting "Clean" Utf-8 Text from a Web Page Scraped with Rcurl
How to Facet a Plot_Ly() Chart
Efficient Calculation of Matrix Cumulative Standard Deviation in R
R Shiny Table Not Rendering HTML
How to Detect Free Variable Names in R Functions
How to Generalize Outer to N Dimensions
Grouped Operations That Result in Length Not Equal to 1 or Length of Group in Dplyr
R: Eval(Parse(...)) Is Often Suboptimal
Force Ggplot Legend to Show All Categories When No Values Are Present
Modifying Ggplot Objects After Creation
How to Append a Whole Dataframe to a CSV in R
Calculating Time Difference Between Two Columns
Adding Empty Graphs to Facet_Wrap in Ggplot2
Calculating Number of Days Between 2 Columns of Dates in Data Frame
Tooltip When You Mouseover a Ggplot on Shiny
Interactive Directory Input in Shiny App (R)
How to Stop Bookdown Tables from Floating to Bottom of the Page in PDF