Why doesn't Devtools respect my dependency constraints in an R package - r

I am not an R programmer. I am a web developer that is used to composer dependency manager for PHP which has .json file that lets you specify package version constraints for your application. Then you run the manager and it resolves your dependencies to a set of versions, which it writes in the .lock file. From that lock file I have a very specific set of package version that does not change when I deploy to my production environment.
I am looking for similar mechanics with R as we are running R in the cloud and we are looking to automate the deployment and we want to be sure we have the exact same package version running in dev as in production.
So to get a similar behavior, I've decided to lock the dependencies in the DESCRIPTION file of my package by specifying an exact version of my package (which not recommended in the docs). So I've made an empty R package with a single dependency (by following this tutorial: https://tinyheero.github.io/jekyll/update/2015/07/26/making-your-first-R-package.html) with the following DESCRIPTION. ananas is just a random name for my random package.
Package: ananas
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors#R:
person(given = "First",
family = "Last",
role = c("aut", "cre"),
email = "first.last#example.com",
comment = c(ORCID = "YOUR-ORCID-ID"))
Description: What the package does (one paragraph).
License: What license it uses
Encoding: UTF-8
LazyData: true
Imports:
anytime (== 0.3.0)
If you check the documentation at http://r-pkgs.had.co.nz/description.html#dependencies and you scroll to "versioning" title (not "version" which is further down). You can see an example clearly stating that it is possible to use exact dependencies version constraints.
Then I tried to use the following commands to install the dependencies and the package itself
Rscript -e 'devtools::install("ananas", lib="r-library", upgrade="never")'
Rscript -e 'devtools::install("ananas", lib="r-library")'
And I have an .Rprofile file located where I run the install command with the following content
.libPaths(c("./r-library", .libPaths()))
Yet, when I got to the r-library folder to check the package anytime. I opened the DESCRIPTION file for the anytime package and I see it is at the latest version of 0.3.7 at the time of writing this which does not correspond to the constraints of exactly 0.3.0 in the DESCRIPTION file of my package.
So my question is why devtools does not respect the version constraints? What am I missing?
Very similar to the following unanswered stackoverflow issue: R doesn't respect maximum version when installing package dependencies

Related

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.

submit an R package with CTAN dependencies to CRAN

I am currently working on an R package that is going to be submitted CRAN within a few weeks. The package needs some latex packages to run. Those latex packages are available on CTAN and injected in the preamble of RMarkdown documents via rmarkdown::latex_dependency().
This is the concept of my actual knit_print method.
#' #export
knit_print.my_class <- function(obj, ...) {
knitr::raw_latex(
to_latex(obj),
meta = list(
rmakrdown::latex_dependency(
"ragged2e"
)
)
)
}
My question is how those dependencies can be specified in a way such that CRAN is going to accept this submission. As far as I can tell, there are four options
submit the package as-is and add installation instructions via the documentation and the SystemRequirements field of the DESCRIPTION file.
include all necessary latex packages in my R package and somehow make them available to the client's latex compiler
add a dependency to tinytex which can install CTAN packages automatically
Throw an error during installation if the dependencies are not met
So far, I used option (1).
My configuration for travis (ubuntu 14.04) is
apt install texlive-latex-extra
tlmgr install standalone
For appveyor (Windows Server 2012 R2 x64), I unpack miktex-portable.exe and add it to the PATH. Then I get the following packages.
mpm --install=standalone
mpm --install=ms
mpm --install=pbox
mpm --install=xcolor
mpm --install=colortbl
mpm --install=mptopdf
What I found out so far
using google to search for external dependencies and CRAN sumbissions only yielded information about C and C++ dependencies, which didn't help my cause.
Looking at some source code revealed that rticles include certain .sty files directly in inst/ which leads me to believe, that (2) is the correct answer. However, rticles defines custom output formats and those don't have to "install" the latex packages since the .sty files are copied to the render directory as part of a template.
magick uses a config file that prevents the installation in case (system) dependencies are not met. It also throws an informative error message that instructs the client how the dependencies can be met.
the tinytex package did not run any compile tests on CRAN when it was submitted. I also can't make tinytex it work on appveyor
I am reasonably familiar with the CRAN Repository Policy and there is generally no provision for external dependencies off CRAN etc.
That said I stretched CRAN a little to by downloading pre-built libraries off GitHub as needed. You could model your package after that.
But what I really think you should do is to ... prepare your pdf vignette locally and then have the R package 'inject' it as is. How to do that is explained eg in this post by Mark and I just converted my RcppAnnoy package to do just that. Of course, YMMV.

How do i keep source files when using R's devtools library function 'install'

I am trying to build an R package (DESeq2) from source so that I can debug it. I've installed all the dependencies required and I'm following Hillary Parker's instructions for creating R packages. I'm running this on CentOS 6.6 using R-3.4.2.
I run :
library("devtools")
install("DESeq2", keep_source=TRUE)
It installs it in the directory with all my other R libraries. When I look at the installed DESeq2 library it is missing all the DESeq2/R/*.R and DESeq2/src/*.cpp files.
QUESTION : Where are these files and why didn't they get installed? This does not seem like the expected behavior.
R uses binary database format for installed packages to pack the objects into a database-alike file format for efficiency reasons (lazy loading). These database files (*.rdb and *.rdx) are stored in the R sub folder of the package installation path (see ?lazyLoad).
Even if
you are looking at the right place to find the installed package (use .libPaths() in R to find the installation folder)
and you have installed the package with the source code (like you did or
via install.packages("a_CRAN_package", INSTALL_opts = "--with-keep.source"))
you will not find R files in R folder there.
You can verify that the source code is available by picking one function name from the package and print it on the console. If you can see the source code (with comments) the package sources (R files) are available:
print(DeSeq2::any_function)
To make the source code available for debugging and stack traces you can set the option keep.source.pkgs = TRUE (see ?options) in your .Rprofile file or via an environment variable:
keep.source.pkgs:
As for keep.source, used only when packages are
installed. Defaults to FALSE unless the environment variable
R_KEEP_PKG_SOURCE is set to yes.
Note: The source code is available then only for newly installed and updated packages (not for already installed packages!).
For more details see: https://yetanothermathprogrammingconsultant.blogspot.de/2016/02/r-lazy-load-db-files.html

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

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

R devtools:document Dependency package not available

Hi I am following the tutorial here from Hilary and here from Hadley Wickham trying to create a dummy package.
However, my package need some external dependencies XML and RCurl in this case, when I run the command document, it will complain that:
> setwd('/home/datafireball/projects/Rprojects/rgetout/rgetout')
> document()
Error: could not find function "document"
> library(devtools)
> document()
Updating rgetout documentation
Loading rgetout
Loading required namespace: XML
Error in (function (dep_name, dep_ver = NA, dep_compare = NA) :
Dependency package XML not available.
>
Here is my DESCRIPTION file.
Package: rgetout
Title: A R package to get all the outlinks for a given URL
Version: 0.1
Authors#R: "Eric Cartman <Eric.Cartman#gmail.com> [aut, cre]"
Description: This package is intended to include as much web extraction functionality as much as possible. It starts with one function. getout will extract
all the outlinks for a given URL with a user-agent that you can customize.
Depends: R (>= 3.0.2)
Imports:
XML,
RCurl
License: MIT
LazyData: true
Here is the source code github repo if you want to get more info.
If you are having problems with this, even when you have the packages installed and loaded, I suggest you to do the following.
Delete the Imports: and Suggests: entries of your DESCRIPTION file.
Make sure you have usethis working by doing library(usethis)
Now start adding the libraries to your DESCRIPTION file, by running the following command on your console: usethis::use_package("dplyr") for any Imports: you need. Repeat this step for every library that is required.
In my case, dplyr was the one refusing to load. You can decide where the package will be located by doing: usethis::use_package("dplyr", "Suggests").
It is assumed that you will have the required tools / dependencies for developing a package when you are
doing so.
utils::install.packages has a dependencies argument that will attempt to install uninstalled packages on which a package depends / (in whichever way they are dependent (suggests/ depends/linkingTo).
devtools::install_github will perform similarly.
Installing a package and documenting it as a component of development are quiet different activities
.

Resources