R can't find packages installed by travis - r

We're trying to add some unit tests to the caret package that get run by travis, but not on CRAN. This saves build time on CRAN and reduces the number of dependencies they have to install to check our package, while letting us run a more complete test suite on travis.
I thought I could simply install the requirements for the test using the r_packages: line in my travis.yml file:
r_packages:
- ROSE
- DMwR
However, my NOT_CRAN=TRUE builds are still failing. (NOT_CRAN=FALSE runs fine as the problematic tests are skipped)
This is really strange, as when I look at the build logs, I see travis successfully installing all the packages I need:
* installing *source* package ‘ROSE’ ...
** package ‘ROSE’ successfully unpacked and MD5 sums checked
** R
** data
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (ROSE)
But when my tests run that depend on those packages, R can't find them:
> library(testthat)
> library(caret)
Loading required package: lattice
Loading required package: ggplot2
>
> test_check("caret")
[1] "Reduced dimension to 3 by default. "
1 package is needed for this model and is not installed. (ROSE). Would you like to try to install it now?1. Error: check appropriate sampling calls by name -----------------------------
1: withCallingHandlers(eval(code, new_test_environment), error = capture_calls, message = function(c) invokeRestart("muffleMessage"),
warning = function(c) invokeRestart("muffleWarning"))
2: eval(code, new_test_environment)
3: eval(expr, envir, enclos)
4: caret:::parse_sampling(i) at test_sampling_options.R:14
5: checkInstall(pkgs)
6: stop()
testthat results ================================================================
OK: 62 SKIPPED: 0 FAILED: 1
1. Error: check appropriate sampling calls by name
Error: testthat unit tests failed
Execution halted
(I think) the relevant line of code is here in caret's source code:
good <- rep(TRUE, length(pkg))
for(i in seq(along = pkg)){
tested <- try(find.package(pkg[i]), silent = TRUE)
if(class(tested)[1] == "try-error") good[i] <- FALSE
}
Why can't the find.package function find packages installed by travis? Do they go in a special, separate library somewhere?
Also, as an aside, how do I make my travis builds for r less verbose? By default they seem to print way too much information (e.g. it echoes all code run by the tests and manual, even code that doesn't error).

When testing your package on Travis, R CMD check appears to be looking for installed packages in the wrong place(s).
I created a small test package to figure this out:
When testing the package on Travis using R CMD check, .libPaths() contains:
c("/tmp/RtmpnQE1WM/RLIBS_29bd3940b7fa",
"/usr/lib/R/library")
When testing the package on Travis using devtools::test(), .libPaths() contains:
c("/usr/local/lib/R/site-library",
"/usr/lib/R/site-library",
"/usr/lib/R/library")
By default, R packages on Travis are installed into /usr/local/lib/R/site-library (i.e. the first entry of .libPaths()). Clearly, R CMD check is looking in the wrong place(s).
In principle, we could use the --library argument for R CMD check to point to the right place, however when you use --as-cran then --library defaults to /usr/lib/R/library.
The easiest solution is probably to install all packages (in particular the "additional" packages ROSE and DMwR) into /usr/lib/R/library. There are many ways to do that. One solution is to add
sudo mkdir -p /usr/lib/R/library
echo 'R_LIBS=/usr/lib/R/library:/usr/lib/R/site-library/' > ~/.Renviron
sudo chmod 2777 /usr/lib/R/library
to the before_install section of your .travis.yml file.

You could clone the r-travis repo and just source from your copy. That would allow you to make it less verbose.
As to "packages not found": dunno. But the Travis instance is a vanilla Ubuntu installation so you can control things by echo'ing into a suitable ~/.Rprofile etc pp. I have found the old r-travis setup to be more convenient for me and recently blogged about one way to dramatically cut test times down by relying more on pre-built r-cran-* .deb packages.
Michael has well over 1000 in his repo, and you could build your own too via a PPA. Time permitting I may write another blog post detailing that...

Related

Package build fails on R 3.6.0 (devel) but not on 3.5.5 (release)

I am writing a package for CRAN, which I test on Travis on release and development versions. The package builds fine on the release version and gives this error on devel:
** testing if installed package keeps a record of temporary installation path
ERROR: hard-coded installation path: please report to the package maintainer and use ‘--no-staged-install’
* removing ‘/tmp/RtmpZ9RX7i/Rinst63414089e04b/PackageName’
-----------------------------------
ERROR: package installation failed
The change in code that caused the build to fail and that relate to a hard-coded path are these lines in the package:
k_extdata <- "extdata"
k_package <- "PosteriorBootstrap"
k_german_credit <- "statlog-german-credit.dat"
data_file <- function(name) {
return(system.file(k_extdata, name, package = k_package))
}
and these lines in the tests:
stan_file <- data_file("bayes_logit.stan")
bayes_logit_model <- rstan::stan_model(file = stan_file)
An online search reveals zero results for this problem. Has anyone found this before, and why does it fail only in the devel version?
This error is triggered by the new Staged Install feature introduced in R 3.6.0. You can read more about this on the official R blog: https://developer.r-project.org/Blog/public/2019/02/14/staged-install/index.html

Rstudio Clean and Rebuild lazy data error

I am trying to develop a R package with RStudio. Lately, I have had no success.
devtools::build(), devtools::reload() and devtools::check() give:
Updating CF documentation
Loading CF
Error in aes(x = gdpPercap, y = lifeExp, size = pop, color = continent, (from mapping.R#1) :
could not find function "aes" or the data.
devtools::check() gives other information, which I list below.
Clean and Rebuild gives:
1] "/Users/PJO/Desktop/CF_0.1.0.tar.gz"
==> R CMD INSTALL --preclean --no-multiarch --with-keep.source CF.2.24
installing to library ‘/Users/PJO/Library/R/3.4/library’
installing source package ‘CF’ ...
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
Error in aes(x = gdpPercap, y = lifeExp, size = pop, color = continent, :
could not find function "aes"
Error : unable to load R code in package ‘CF’
ERROR: lazy loading failed for package ‘CF’
* removing ‘/Users/PJO/Library/R/3.4/library/CF’
* restoring previous ‘/Users/PJO/Library/R/3.4/library/CF’
Exited with status 1.
My search has shown that other developers have experienced similar problems. I believe that it connected to (a) devtools and some (b) lingering code. I cannot prove it.
The following efforts have not worked: (1) restarting R, (2) removing invisible files, .R*, (3) rebooting RStudio, (4) debugging all functions with RStudio debug() before committing them to the R package, ... . The error suggests that I have not loaded all the data or required libraries. The above error directs attention to the R library "gapminder." It calls "aes" therefore, it should load. With or without loading "gapminder," I obtain the same error. So, I suspect some hidden files are lurking in the background.
To compare, I tested an old version of my CF package. It works:
==> R CMD INSTALL --preclean --no-multiarch --with-keep.source CF
installing to library ‘/Users/PJO/Library/R/3.4/library’
installing source package ‘CF’ ...
** R
** data
* moving datasets to lazyload DB
** inst
** preparing package for lazy loading
** help
* installing help indices
** building package indices
** testing if installed package can be loaded
DONE (CF)
Other attempts include using browser() and traceback() from Rstudio debug() fail. They fail because of the Clean and Rebuild fails before debug() is called.
Some devtools::check() failures for my latest CF package:
The Title field should be in title case, current version then in title case:
‘Stochastic traffic performance and car-following modeling tools’
‘Stochastic Traffic Performance and Car-Following Modeling Tools’
── Install failure ─────────────────────────────────────────────────────────────────────────
checking for empty or unneeded directories
Removed empty directory ‘CF/inst/extdata’
Removed empty directory ‘CF/inst’
looking to see if a ‘data/datalist’ file should be added
building ‘CF_0.1.0.tar.gz’
Some devtools::check() failures for my older CF package:
The Title field should be in title case, current version then in title case:
‘A package for performing analyses with stochastic traffic performance and car-following models’
‘A Package for Performing Analyses with Stochastic Traffic Performance and Car-Following Models’
plotfollow2: no visible binding for global variable ‘leff’
Undefined global functions or variables:
leff
These errors do not cause Clean and Rebuild error.
As you can see, I have run out of things to try. For another, I am experienced enough to know if I am overlooking something. For example, I am taking the Title problem seriously. To be honest, the suggested corrective action does not make sense to me.
Help would be greatly appreciated.
Paul

checkCompilerOptions Error while installing package (littler/Docker)

On its last line, this Docker file calls littler::install.r to install Rcpp RcppEigen and matrixStats.
The whole code was working like a charm a couple of months back. Now, it bombs at that last step. More precisely, Rcpp and RcppEigen still install perfectly, but when it comes to installing matrixStats, I get:
installing to /usr/local/lib/R/site-library/matrixStats/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error in get(name, envir = asNamespace(pkg), inherits = FALSE) :
object 'checkCompilerOptions' not found
Calls: ::: -> get
Execution halted
ERROR: loading failed
* removing ‘/usr/local/lib/R/site-library/matrixStats’
The downloaded source packages are in
‘/tmp/downloaded_packages’
Warning message:
In install.packages(f, lib, if (isMatchingFile(f)) NULL else repos) :
installation of package ‘matrixStats’ had non-zero exit status
It's an error I never had before and have trouble locating where it is even coming from. What could be causing this problem? Any info would already help a lot.
However, with R-devel using rocker/r-devel,
docker run --rm -ti rocker/r-devel /bin/bash
RD
install.packages("matrixStats")
Gives the same error. I'm guessing this is another R-devel change which takes away things we took for granted before, in this case something to do with compiler package. I don't however have a solution, yet. Just (re-)installing or attaching compiler doesn't help.
Update
Using R CMD INSTALL --no-byte-compile allows backports to install for me, which was the package I was having trouble with.
From the top of my head I'd blame a change in matrixStats [ but see below and it appears blameless ] -- I am somewhat familiar with all the other moving parts and not aware of changes or bugs.
One thing that is fishy though is the trailing line break:
RUN install.r Rcpp RcppEigen matrixStats \
You may try without it.
Edit: And for what it is worth I just fired up our standard base layer Docker image r-base via
docker run --rm -ti r-base /bin/bash
and invoked
install.r Rcpp RcppEigen matrixStats
which executed just fine.
So if sonething is wrong with that other Docker container you may have to take it up with its author and work through his changes relative to our Dockerfile he seems to have used as a base.

Package dependency issue when testing for submissin to CRAN

I am developing an R package for which I wrote some test files using R package testthatand placed the files under tests folder. I ran R CMD build on a Linux machine with R version 3.0.0. The command failed because testthat package requires R version at least 3.1.0.
Two following things I can do, but I am not sure which is better.
I can remove whole things in tests folder, so that my R package will also work for R version less than 3.1.0. As I notice, test files are not required for building an R package. Those are only useful for the developer.
I can keep all test files, but explicitly mention Depends: R (>= 3.1.0) in the DESCRIPTION file. The downside is that: (1) the package will be available to less users; and (2) more important, it depends on testthat package. Whatever updates there might affect my package potentially.
Which one do you think is better?
[update]
I followed the suggestion from # hrbrmstr, which is, I first built the package using R 3.1.0, and then check it on a Linux machine with R 3.0.0. But I still failed. The log is as follows.
* checking package namespace information ... OK
* checking package dependencies ... ERROR
Package suggested but not available: ‘testthat’
The suggested packages are required for a complete check.
Checking can be attempted without them by setting the environment
variable _R_CHECK_FORCE_SUGGESTS_ to a false value.
Any ideas to fix this issue?Or should I take approach 1 or 2 as stated above?

Why does Travis CI fail to build b/c R package is unavailable, while passing devtools::check()?

The package causing the problem is apparently numbers. My best guess as to why is because numbers was built under an older version of R (as is indicated by the warning message I get when I library(numbers) in R).
But I'm pretty new to Travis CI and R packages in general, so I could be missing something.
The Travis CI log is here
I'm confused not only because the R pacakge numbers is available to me (OSX), but also because my package passes the devtools::check(). My package passed on Travis previously (when it only depended on ssh.utils), so I'm pretty sure the problem is somehow related to numbers.
Is this Travis error message related to the way I've asked Travis to install a package? Is there a setting I can change in my Travis yml to allow the build to pass? Any help would be appreciated.
From your logs, the package gmp install is failing, as Travis systems don't have gmp installed:
* installing *source* package ‘gmp’ ...
** package ‘gmp’ successfully unpacked and MD5 sums checked
creating cache ./config.cache
checking for __gmpz_ui_sub in -lgmp... no
configure: error: GNU MP not found, or not 4.1.4 or up, see http://gmplib.org
ERROR: configuration failed for package ‘gmp’
* removing ‘/usr/local/lib/R/site-library/gmp’
See this answer here for how to install it, you can probably add the code:
sudo apt-get install libgmp3-dev
to your Travis config file (not tested).

Resources