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

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)

Related

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.

Do packages installed from Github need Rtools?

I am creating my first package, which shall be installed through Github. I thought that Rtools was needed only for the person creating it. However, people that tried to install it using Github were asked to update Rtools. Is this really necessary?
Doing some research, I found this: https://community.rstudio.com/t/missing-rtools-should-i-be-worried/27817
One of the answers says the following:
"This means that if you are going to install packages that need
compilation, you also have to install Rtools in your system. "
This is the repo with the package: https://github.com/datazoompuc/PNAD_Covid/tree/master/R/datazoom_pnad_covid
What does this actually mean? How do I know that my package needs compilation?
I thought that Rtools was needed only for the person creating it.
Yes, if and only if you distribute it as a binary. Then the creator uses Rtools to compile and link, and the user just installs, and enjoys.
That is how CRAN works as CRAN compiles for Windows users.
GitHub, however, is foremost a source repository so the installation from GitHub is using a source mode ... and every user will need to compile, and hence have Rtools. (Unless the package and all its depedencies are R-code only.)
You can also have a package repository on GitHub using e.g. the drat package to create it, but that is getting us a little further from the original question.
Your package "needs compilation" — i.e. needs Rtools to install from source (on Windows) — if it contains C or Fortran components, i.e. if you have anything in the src/ directory of your package ...
If you, the package author, don't know if you have C or Fortran code as part of your package, then you almost certainly don't.
It's quite possible that devtools is being overzealous, i.e. detecting that users have a not-most-current Rtools and suggesting (requiring??) that they update it, even though it's not needed for this installation.

How to force devtools to install packages in remotes

devtools package introduces a nice concept of adding dependancies not available in CRAN, into DESCRIPTION file (described in the vignette). However, I have not been able to figure out how to get it to install the dependancies automatically. The vignette linked above certainly hints that is possible and the install command certainly parses for the "remote" (got an error when they were not specified correctly), however, it only installed dependancies from CRAN. Anybody has ideas if there are some parameters I should specify to make the installation automatic?
Thusfar, I have tried install, install_bitbucket and install_local. install managed to download all the dependancies available in CRAN. install_bitbucket did the same and install_local just did not work at all.
The Remotes: field is used to tell devtools where to look for the packages that are listed in the standard Depends:, Imports: and Suggests:.
So make sure that you have the package listed in the appropriate standard field, and its source listed in Remotes. Then running the following should install these packages from the Remotes source:
devtools::install_deps()

installing an archived package

The package is available on this website.
http://cran.r-project.org/src/contrib/Archive/rlandscape/
When I use:
install.packages("rlandscape",
repos = "http://cran.r-project.org/src/contrib/Archive/rlandscape/",
type="source")
I get the following error:
package 'rlandscape' is not available (for R version 3.1.2)
I have tried older versions too but no luck..
The devtools package has a function that can install archived versions. Try:
library("devtools")
install_version("rlandscape",version="1.0",
repos="http://cran.r-project.org")
(You should be able to use repos=getOption("repos")["CRAN"] instead, but it looks like your repos option is slightly messed up, i.e. the URL is missing the http://.)
(The repos argument is necessary to work around what I think is a glitch in install_version, i.e. it assumes that repos is a length-1 character vector.)
This should, I think, also automatically install appropriate dependencies -- although it's a bit of a catch-22 if they are in the CRANextra repository for Windows, since that has to be suppressed in order to get install_version to work ...
It may also be the case that install_version automatically assumes that you want the package and all dependencies installed as source (not binary) installations, in which case you will need to have compilation tools installed. The rlandscape package doesn't actually have any compiled code included, but its dependencies do ...
This is an old (archived) package that is no longer supported. If you really need it, you can install it using R CMD INSTALL but you need also to install all its dependencies manually.
Installing your desired package gave me the following:
>R CMD INSTALL ~/Downloads/rlandscape_1.0.tar.gz
* installing to library ‘/Users/mohamedahmed/Rlibs’
ERROR: dependencies ‘spatstat’, ‘deldir’, ‘gWidgets’, ‘gWidgetsRGtk2’ are not available for package ‘rlandscape’
* removing ‘/Users/mohamedahmed/Rlibs/rlandscape’
I am not sure all dependencies are still available on CRAN, but it seems to be challenging task.

Package installation issues with R 3.1.0

My Fedora system (Fedora 20, all up to date) has just had R updated to version 3.1.0. Since then, I've had issues installing multiple packages. glmnet failed previously, and now I'm having trouble with treemap. More specifically, I get an error during treemap installation that httpuv has zero exit status.
I never had issues with the previous version of R. Any reason this version should have such problems??
There could be many causes to do with your OS, version, permissions, other installed packages/software, etc, etc. Without seeing the full error message it's hard to know.
One possibility specific to httpuv is root privileges. I've noticed a few threads on various forums when searching for installation errors with this package and Linux, many of them mentioning root v. non-root issues. In another case, libuv needed to be upgraded.
I encounter package installation problems daily and I have some more general work-arounds as well. Hopefully one of these will solve your problem.
Install the package from source
download.file(url="http://cran.r-project.org/src/contrib/httpuv_1.3.0.tar.gz", destfile = "httpuv.tar.gz")
install.packages("httpuv.tar.gz", type = "source", repos = NULL)
Install using devtools via GitHub if the package supports it
Install RTools and re-try your package installation
Install an older version of the package
If those above do not work, then I dig deeper by referring to advice given to me by a VP of IT in my company. These comments were made in reference to frequent package installation problems I encountered when switching from Windows to Solaris:
There are two types of install/make problems. Missing .h files
and/or missing .so/.a libs. The reason for these are multiple:
1.- the package that delivers these is not installed. This means that those files cannot be found anywhere in the /usr tree. Solution is
install right package, make sure the files are there
2.- the includes are not found by the install configurator. This means some environment variable or install option is not properly set (this
is our case for RODBC). Figuring out which variable to set is
challenging without looking at the package documentation [fortunately, documentation is not hard to find!]
3.- the libs are not in the LD_LIBRARY_PATH, easy to fix.
4.- There is a deeper compile/link error, meaning the package is not compatible with the rest of the sw, or has not been properly ported.

Resources