Using R package source files in packrat (rather than CRAN) with Travis-CI

Ben

I'm working with an R package that is an RStudio project, and I'm using packrat to keep a local copy of the source of the packages I depend on for my project.

I've got Travis-CI checking my R package each time I make a commit, but each time Travis builds my package it gets the latest version of the dependent packages, rather than the versions I've got in my packrat/ directory.

I can see in richfitz/wood that he appears to have achieved this goal with this in his .travis.yml file:

env:
 USE_PACKRAT=1

and a fairly complex make/packrat.mk file which makes it all work.

My question is what is the simplest way to configure my project (e.g. my .travis.yml file) to tell the Travis machine to get the packages from my packrat/ directory on github, and not from CRAN?

Ben

After much trial and error and further reading, it seems that this will do it, with a .travis.yml file like this:

# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r

language: R
sudo: false
cache: packages
install:
  - R -e "0" --args --bootstrap-packrat
warnings_are_errors: false

The key lines in the above file are:

install:
  - R -e "0" --args --bootstrap-packrat

This will start R, and builds the R packages in the local packrat directory so that they are available in the Travis machine.

After that, travis will continue and attempt to build the package, and will not need contact CRAN to get the dependencies because they are already available (assuming packrat is working as expected).

I discovered this trick here: https://travis-ci.org/ChowHub/paper-pattern-similarity/builds/127262823 and at https://github.com/rstudio/packrat/issues/158. I've got it working here: https://travis-ci.org/benmarwick/mjbtramp/builds/157747326

The advantage of this is we can build on travis with the exact same packages that we're using locally. We don't have to get the latest packages from CRAN when we build on travis, now we can have more control of the package versions that travis builds with in our project.

The disadvantage is that the build time on travis is substantially increased. One of my projects went from 2-3 mins to 13-15 mins after switching to packrat.


UPDATE After Noam's question below and Jim's comment, it seems we can cache the packrat packages using cache: like this:

# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r

language: R
sudo: false
cache:
  directories: $TRAVIS_BUILD_DIR/packrat/
  packages: true
install:
  - R -e "0" --args --bootstrap-packrat
warnings_are_errors: false

In my use-case, this has reduced the times substantially, back to 1-2 mins.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Specify valgrind options to R package on Travis CI

Travis CI R package error in documentation

travis-ci build for r package

Using R with git and packrat

R: jsonlite package - fromJSON converts json files to character rather than intended list

Error using Travis CI with R package: 'roxygen2' >= 5.0.0 must be installed for this functionality

what is the advantage of using input->post() rather than $_POST[''] in CI

Where does Travis CI put my source files?

Download Debian source files for stable rather than unstable

R package dependency error on travis-ci but not local machine

Installing Remote R Package to Databricks Cluster Rather than Notebook

Using Travis CI with Android

Advantages of using named pipes and sockets rather than temporary files

Simple image viewer that is using trash rather than permanently deleting files?

Can using PCManFM rather than Nautilus/Files in 18.04 cause problems?

R: instructions for unbundling and using a packrat snapshot

using column numbers for grouping in data table rather than names in R

In R, using scientific notation 10^ rather than e+

Aggregate function in R using column index numbers rather than names

Issue Building C++ package with cmake: using Python .dylib, using 2.7 rather rather than 3.8, OS X

VS Code Python Debug uses virtual files rather than actual source code

Open Source Website Deployed with Travis-CI

CPack Source archive empty on Travis CI but not locally

Install package on Travis-ci with sudo:false

using this rather than $(this) in an .each() call

Html code as IFRAME source rather than a URL

Installing specific R package from specific branch from github repo on travis-ci

Travis CI build error with my R package that uses C++, Rcpp and RcppArmadillo

How can I refresh a data source from an R package automatically? Specifically the coronavirus CRAN package data