Jonathan Olmsted

R Packages in Subdirectories on Travis CI

| Comments

Travis CI is a really nice tool to provide automated builds of projects. It supports different languages (e.g., C++, python, Ruby) and allows user configuration of the build environments before testing the build. Effectively, you give Travis CI a set of instructions on how to set up a virtual machine. The VM then follows these instructions and attempts to build your project. This is all done in nearly real time. What I like the most about this setup is that it’s simultaneously testing the build and your explicated assumptions about dependencies. Officially, R isn’t “supported”. But, the platform can and has been used for R package development.

  • Yihui Xie wrote a post about this last year, but I did not really appreciate the potential of the system then.

  • I had noticed the Travis CI status badge (e.g. “Build Status Example”) on a few of Hadley Wickham’s github repos, but did not really dive into it.

  • Then, after looking at the github repo for Dirk Eddelbuettel and Co’s new headers-only R package for the Boost codebase, I realized I wanted to look into Travis CI more.

So, I did.

In particular, I wanted to start testing builds of RcppTN beyond my local machine in the lead up to an initial CRAN release.

Simple Tweak for Subdirectory Builds

Installing an R package that is published in a github repo is made insanely simple with Hadley Wickham’s devtools package. And, it even handles R packages deeper than the root level. The instructions here show use of that feature.

However, even though Travis CI has tight github integration (e.g. testing the build on every commit), all of the examples I had seen used a Travis CI configuration (i.e. .travis.yml) for an R package whose contents were at the root of the github repo. Not so for RcppTN!

I have not taken the time to think about the cleanest way to generalize the “fix”, but instead of the default

Sample Configlink
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Sample .travis.yml for R projects.
#
# See README.md for instructions, or for more configuration options,
# see the wiki:
#   https://github.com/craigcitro/r-travis/wiki

language: c

before_install:
  - curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh
  - chmod 755 ./travis-tool.sh
  - ./travis-tool.sh bootstrap
install:
  - ./travis-tool.sh install_deps
script: ./travis-tool.sh run_tests

on_failure:
  - ./travis-tool.sh dump_logs

notifications:
  email:
    on_success: change
    on_failure: change

I needed the following:

Example of Change
1
2
3
4
5
6
7
install:
  - cd ./myRpkg
  - ../travis-tool.sh install_deps
script: ../travis-tool.sh run_tests

on_failure:
  - ../travis-tool.sh dump_logs

From this, it’s clear to see that the Travis CI build system is less like make and more what you’d do if you were typing the commands manually at a terminal. With make, any changes to the working directory path are reset after each command in a recipe. So, with make

Make Example 1
1
2
target :
    cd src ; python ./script.py

is different from

Make Example 2
1
2
3
target :
    cd src
    python ./script.py

But, with Travis CI, it’s just like typing things in a shell. Once you’ve cd-ed into a directory, you stay there until you explicitly say to navigate elsewhere.

Getting Started

If you need information on getting started with Travis CI and R, see here.

Comments