Ben Ben - 2 years ago 95
R Question

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

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


I can see in richfitz/wood that he appears to have achieved this goal with this in his


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

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

Ben Ben
Answer Source

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

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

The key lines in the above file are:

  - 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: and at I've got it working here:

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download