Make CRAN R package suggest GitHub R package
Asked Answered
F

2

5

I want to use the R package BOLTSSIRR available on GitHub in my R package, which I want to upload to CRAN.

I listed BOLTSSIRR under Suggests: in the DESCRIPTION file and made the link to GitHub available using Additional_repositories: https://github.com/daviddaigithub/BOLTSSIRR.

However, running R CMD check --as-cran I get:

Suggests or Enhances not in mainstream repositories:
  BOLTSSIRR
Availability using Additional_repositories specification:
  BOLTSSIRR   no   ?                                          
  ?            ?   https://github.com/daviddaigithub/BOLTSSIRR
Additional repositories with no packages:
  https://github.com/daviddaigithub/BOLTSSIRR

So the GitHub link does not seem to get recognized in the check. Might I have to change something here?

Flashy answered 29/3, 2021 at 7:4 Comment(3)
It's been answered over here #30493888Gainless
Does this answer your question? Create an R package that depends on another R package located on GitHubFlorescence
@WiktorGustafsson @Florescence Thank you. Unfortunately, this does not seem to answer my question yet. The Remotes: field does not seem to get recognized in the check. I get: "* checking CRAN incoming feasibility ... WARNING Unknown, possibly mis-spelled, fields in DESCRIPTION: 'Remotes' Strong dependencies not in mainstream repositories: BOLTSSIRR". Note that in the case of the other question, both packages were on GitHub, whereas my package needs to be uploaded to CRAN.Flashy
D
7

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!

Downtrend answered 29/3, 2021 at 10:0 Comment(7)
Thank you for this elaborate helpful answer! Currently I have an issue in step 5: I tried: drat::insertPackage(file="pathtofile/BOLTSSIRR_0.1.0.tar.gz") and got Error: Directory ~/git/drat not found. I guess, I have to specify the argument repodir . Unfortunately, I'm not very familar with GitHub. So I don't understand the help page regarding repodir. What should I use for repodir?Flashy
I managed to upload the package, but I get: "* checking CRAN incoming feasibility ...Warning: unable to access index for repository github.com/RomanHornung/drat/src/contrib: cannot open URL 'github.com/RomanHornung/drat/src/contrib/PACKAGES' Suggests or Enhances not in mainstream repositories: BOLTSSIRR Availability using Additional_repositories specification: BOLTSSIRR no ? ? ? github.com/RomanHornung/drat Additional repositories with no packages: github.com/RomanHornung/drat" What could be the problem here?Flashy
I think you haven't pushed things to Github. I'd expect to find the repository at RomanHornung.github.io/drat (step 2 should have created this), but don't see anything there; in the source location, github.com/RomanHornung/drat, I see a repos but it doesn't have BOLTSSIRR in it. (That should have happened after step 5, but maybe you need an explicit push to Github that I didn't ask for.)Downtrend
Thank you again! I tried again and after insertPackage(file="path1/BOLTSSIRR_0.1.0.tar.gz", repodir="path2/romanhornung.github.io"), it was in my local repo. Then I wrote git add --all, git commit -m "Second commit", and git push -u origin master. This pushed the changes to RomanHornung/romanhornung.github.io, but they are not visible on https://romanhornung.github.io and romanhornung.github.io/drat still does not exist (or it has no content) even though it says "Your site is published at romanhornung.github.io/drat" on the "RomanHornung/drat" page. What could be wrong?Flashy
I'd expect to see it in github.com/RomanHornung/drat/tree/master/docs/src/contrib, but it's not there. On your home system, that's docs/src/contrib of your fork of the drat-base repository. You need to tell Github to publish from there; I forget the details of how to do that.Downtrend
Thanks again! I now got it to working: Before step 5 I cloned the drat repository to my local computer using git clone https://github.com/RomanHornung/drat and then deleted the files in the folders docs/src/contrib and docs/bin/windows/contrib/4.0. Also before step 5 options(dratBranch="docs") was necessary. After step 5, being in the drat directory on my computer I wrote: 1) git add ., 2) git commit -m "Added package", 3) git push origin master. I executed the git commands from the Terminal in RStudio.Flashy
Thanks @user2554330, I know it's a somewhat stale thread, but it was really helpful.Equipoise
R
1

Answering since I cant comment. @user2554330 answer is correct, and will fix the additional package not being available. However, you may still get a NOTE about:

Package suggested but not available for checking: <yourpackage>

which you should be able to explain is a result of the drat-hosted library, but the package will not be available for e.g. vignettes/examples in checks. This note in CRAN policies still applies:

A package listed in ‘Suggests’ or ‘Enhances’ should be used conditionally in examples or tests if it cannot straightforwardly be installed on the major R platforms. (‘Writing R Extensions’ recommends that they are always used conditionally.)

In my submission I was getting errors in examples due to not being able to find a package hosted in a drat repo that was listed in Additional_repositories. One way around this is to use @examplesIf requireNamespace("yourpackage", quietly = TRUE) instead of @examples in roxygen comments or conditionally run stuff in vignettes with

if (requireNamespace("yourpackage", quietly = TRUE)) {
  result = yourpackage::function()
  # ...
}
Razz answered 15/11, 2023 at 22:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.