Create an R package that depends on another R package located on GitHub - r

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.

This question seems to have been answered quite recently, addressed in this issue of the devtools' github repository.
Package developer POV:
do:
usethis::use_package("jvamisc")
devtools::document()
to add the dependency in the Imports field of your DESCRIPTION file.
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:
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”)
Restart the R Session on unload/reload the devtools package.
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.

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

Related

Make CRAN R package suggest GitHub R package

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?
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 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.)
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

I'm developing an R package in Github (ConceptionTools) that depends on another R package (CreateFlowChart), also in Github. I have followed the instructions for defining remote dependencies. My DESCRIPTION file includes:
Imports: CreateFlowChart
Remotes: github::IMI-ConcePTION/CreateFlowChart
However, when I install my package, with the command:
devtools::install_github("IMI-ConcePTION/ConceptionTools")
This dependency is not installed. I simply get "skipping 1 packages not available: CreateFlowChart". It doesn't appear to be trying to use the Remote, since there is no error related to Github.
When I install the dependency directly, that works:
devtools::install_github("IMI-ConcePTION/CreateFlowChart")
Does anybody have any idea of what could be going on here? I'm racking my brain, as it seems to be a quite straightforward case of what the documentation shows. I'm using R 4.0.3 (on Windows 10) and devtools 2.3.2.
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.

Use GitHub Package R Actions

I was trying to use actions in a package I wrote. The issue is that the package actions uses remotes in its setup to install CRAN only packages.
Since the package I am working on depends on a non CRAN package that is present on GitHub, both coverage and R CMD checks fail. I tried to avoid this by naively downgrading to an earlier version of the package in depends but some functions are not exported. I am wondering if someone knows a workaround that might help(I cannot open an issue at actions since their support.md file discourages this).
If your package depends on a non-CRAN package, you must include under Remotes: rather than just Imports: in your DESCRIPTION file. Here you would have:
Imports:
actions
Remotes:
r-lib/actions
This will pass checks, but there is no work around for publishing to CRAN if any of your dependencies are not on CRAN, thus you'll get a warning if any packages are present in the Remotes field.
The alternative using Travis is adding r_github_packages: r-lib/actions to your .travis.yml.
After some time, I have found a workaround that for now is good enough if you want to test for the development version(like I wanted). You should include an install_github command in the check.yaml file. Here's an example:
- name: Install dependencies
run: |
install.packages(c("remotes","testthat"),dependencies=TRUE)
remotes::install_github("tidyverse/dplyr")
remotes::install_cran("covr")
shell: Rscript {0}
The above snippet fixed my issue because I wanted to depend on a future dplyr version. You can view the full yaml file here.

how to make devtools install_github to install dependency packages from CRAN instead of compiling source

EDIT: see edit in end.
I have a R package in github and I'm using devtools::install_github to install it, which also install dependency packages.
Recently this process will install httpuv as source package, but compiling it in Mac meet errors with automake (something like this). I installed automake, then there was error with clang: error: unsupported option '-fopenmp'.
The issue and the possible solutions 1 2 seemed to be quite complicated. I think the CRAN version of httpuv probably will work for me, and I don't want my users to go through so many errors and fixing compiler errors.
I'd like to just install all dependency packages from CRAN in binary. For some packages that do need the more up to date version, I have specified it in my package description with remote section.
I checked install_github, then install, then install.packages. It seemed that the default behavior for binary vs source package is
An alternative (and the current default) is "both" which means ‘use
binary if available and current, otherwise try source’. The action if
there are source packages which are preferred but may contain code
which needs to be compiled is controlled by
getOption("install.packages.compile.from.source").
My getOption("install.packages.compile.from.source") is interactive. This is actually a preferred behavior for me. However I never see the interactive prompt.
I tried to give a type = "binary" parameter in install_github, but it doesn't seem to work, maybe it's not passed to every dependency package install?
EDIT:
I found the situation is a little bit more complex:
my app specified to install shiny github version via remote in description. shiny specified to install httpuv github version in remote section too. So this is actually the intended behavior.
I'm not sure if there is a solution available, other than require CRAN version of shiny in my package.
EDIT 2: It's more complex than my previous findings.
I removed remote section in my package description, supposedly only CRAN version is needed. However install_github still install most dependencies from github.
I finally found out that I have these dependencies github version installed, so their description in my local disk have the github remote information, and install_github found this information and "upgrade" them again, even when some of them have no change.
So I need to uninstall them first, only use CRAN version.
The really problem here is that if a dependency package is already new, it should not be installed. It could be a bug of devtools.
install_github passes arguments to devtools::install, and there upgrade_dependencies= FALSE and maybe even dependencies = FALSE might be what you're after:
install_github("you/urPackage", upgrade_dependencies = FALSE)

installing package from R-forge fails [duplicate]

This, question, is, asked, over, and, over, and, over,
on the R-sig-finance mailing list, but I do not think it has been asked on stackoverflow.
It goes like this:
Where can I obtain the latest version of package XYZ that is hosted on R-forge? I tried to install it with install.packages, but this is what happened:
> install.packages("XYZ",repos="http://r-forge.r-project.org")
Warning message: package ‘XYZ’ is not available (for R version 2.15.0)
Looking on the R-forge website for XYZ, I see that the package failed to build.
Therefore, there is no link to download the source. Is there any other way
to get the source code? Once I get the source code, how can I turn that into a
package that I can load with library("XYZ")?
R-Forge may fail to build a package for a few different reasons. It could be that
the documentation has not been updated to reflect recent changes in the code. Or,
it could be that some of the dependencies were not available at build time.
You can checkout the source code using svn. First, search for the project on the
R-Forge website and go to the project home page -- for example http://r-forge.r-project.org/projects/returnanalytics/
Click the SCM link to get to a page like this http://r-forge.r-project.org/scm/?group_id=579
This page will tell you the command to use to checkout the project. In this case you get
This project's SVN repository can be checked out through anonymous access with the following command(s).
svn checkout svn://svn.r-forge.r-project.org/svnroot/returnanalytics/
If you are on Windows, you probably want to download and install TortoiseSVN
Once you have installed TortoiseSVN, you can right click in a Windows Explorer window and select
"SVN checkout". In the "URL of repository:" field, enter everything except the
"svn checkout " part of the command that you found on R-Forge. In this case, you'd
enter "svn://svn.r-forge.r-project.org/svnroot/returnanalytics/".
When you click OK, the project will be downloaded into the current directory.
If you are on a UNIX-alike system (or if you installed the command line client tools
when you installed TortoiseSVN for Windows, which is not the default), you can
type the command that R-forge gave you in your terminal (System terminal, not the R terminal)
svn checkout svn://svn.r-forge.r-project.org/svnroot/returnanalytics/
That will create a new directory under the current working directory that
contains all of the files in the package. In the top level of that directory
will be a subdirectory called "pkg". This particular project (returnanalytics)
contains more than one package.
ls returnanalytics/pkg
#FactorAnalytics MPO PApages PerformanceAnalytics PortfolioAnalytics
But some R-forge projects only have a single package. e.g.
svn checkout svn://svn.r-forge.r-project.org/svnroot/random/
#Checked out revision 14.
ls random/pkg
#DESCRIPTION inst man NAMESPACE R
Now that you have a local copy all of the code, if you would like to be able to
install the package, you have to build it first.
A WORD OF CAUTION: Since R-Forge failed to build the package, there is a good chance
that there are problems with the package. Therefore, if you just build it, you may find
that some things do not work as expected. In particular, it is likely that there
is missing or incomplete documentation.
If you are on a UNIX-alike system, the package can be built and installed relatively easily. For a multi-package project like returnanalytics, if you want to install, e.g. the
PortfolioAnalytics package, you can do it like this
R --vanilla CMD INSTALL --build returnanalytics/pkg/PortfolioAnalytics
"PortfolioAnalytics" is the name of the directory that contains the package that
you want to build/install. For a single-package project, you can build and install like
this
R --vanilla CMD INSTALL --build random/pkg
If you would like to build/install a package on Windows, see this question and follow the two links that #JoshuaUlrich provided
More information can be found in R Installation and Administration, the R-Forge User Manual, and the SVN manual.
If (and only if) you have the appropriate toolchain for your OS, then this may succeed:
# First download source file to your working directory
# As an example use browser to download pkg:partykit from:
# http://download.r-forge.r-project.org/src/contrib/partykit_1.1-2.tar.gz
# Move to working directory
# Or in the case of returnanalytics (which is a bundle of packages):
# http://r-forge.r-project.org/R/?group_id=579 and download the tar.gz (source)
# Then in R:
install.packages( "partykit_1.1-2.tar.gz", repo=NULL, type="source")
# for the first of the ReturnAnalytics packages:
install.packages( "Dowd_0.11.tar.gz", repo=NULL, type="source")
These direction should be "cross-platform". I'm not sure the directions in the accepted answer are applicable to Macs (OSX). (I later confirmed that they do "work" on a Mac but found the process more involved that what I suggested above. They do result in a directory that do contain the packages in a form that should succeed with R --vanilla CMD INSTALL --build pathToEachPackageSeparately)
It is also possible that the current version of the package you are trying to install requires a newer version of R, for example, you may see error like:
"ERROR: this R is version 2.15.0, package 'PerformanceAnalytics' requires R >= 3.0.0"
then you can try to update your R
or, if you are facing the same situation with me, which is trying to use pqR (currently using R version 2.15), you can find the out-of-date achieved package here:
http://cran.at.r-project.org/src/contrib/Archive/PerformanceAnalytics/
You can get here from R-Forge packages page -> "Stable Release: Get PerformanceAnalytics 1.4.3541 from CRAN" -> Old sources: PerformanceAnalytics archive
for example, you will find package PerformanceAnalytics version 1.1.0 just requires R >= 2.14
Good luck
Alternatively, you can install the particular package from GitHub, if it has a repo at GitHub.
I ran install.packages('ggfortify'), and got
Warning message: “package ‘ggfortify’ is not available (for R version
3.3.2)”
ggfortify was the GitHub repo for the same package.
The devtools library allows you to install a package from GitHub directly with install_github('username/repo').
library(devtools)
install_github('sinhrks/ggfortify')

Resources