submit an R package with CTAN dependencies to CRAN - r

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.

Related

Is there a way to 'install' R packages without running install.packages()?

We are testing how to run R in the cloud in a secure isolated environment that is blocked from CRAN and also cannot use packages.install(). We defined an environment which is based on R essentials Anaconda's bundle, still we would like to be able to customize it on demand with extra packages. Is there a way to be able to simulate packages.install(), e.g. by offline downloading the package, zip it, copy to the secure environment and unzipping it to a specific location in the library folder?
thanks!
You can download the package from CRAN as a zip and then transport it to the isolated PC as a file. For example, here is the link to dplyr on CRAN: https://cran.r-project.org/web/packages/dplyr/index.html
Then use the code below to install the local file:
install.packages("~/Downloads/dplyr_1.0.7.zip", repos = NULL)
On Windows you might require Rtools. At least there was a Warning about it but the package still installed.
For Linux machines, you can build the package from source using the tarball from the same page:
install.packages("~/Downloads/dplyr_1.0.7.tar.gz", repos = NULL, type = "source")
In both cases you need to take care of dependencies yourself as they are not checked while installing through this method (look at the "imports" field on the CRAN website for the package).

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!

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)

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

Add non-github dependencies to github R package?

I am building an R package and posted it on github. It is supposed to depend on stringr ... yet despite adding it to the "depends" and "imports" portions of the DESCRIPTION, it seems to have issues installing automatically (is it looking for stringr on github also?).
Here is the command I am running (imagine a fresh R install):
install.packages("devtools")
devtools::install_github("tcarpenter216/packagename")
[replaced my packages name above with 'package name'] ... this is returning the following error:
Downloading GitHub repo tcarpenter216/packagename#master
Error in pull_off("#(.*)$") :
cannot open file '/Users/tcarpenter/Library/R/3.2/library/stringr/R/stringr.rdb': No such file or directory
Any idea how to put dependencies on a package hosted on github? Is it obvious what I'm doing wrong?
You are confusing packages, packages dependencies and what repositories such as CRAN can do -- with just dropping code onto GitHub.
GitHub source code repositories do not resolve dependencies.
GitHub source code repositories are not R code repositories.
However, you can turn them into such R code repositories, and that is what my drat packages (on CRAN and GitHub) does. So see its simple documentation, included in the package. It fills the void you identified here.

Resources