8

I would like to set up Travis CI for an R project hosted on Github that isn’t a package. Unfortunately, the official R Travis support seems to be pretty hard-wired to packages (which, to be fair, makes sense).

Is there any chance to get this working for non-package code, or is my only recourse to branch r-travis and patch it according to my specifications? I don’t feel competent enough to do this easily.

Here’s my failing Travis configuration:

language: R

r_github_packages:
    - klmr/modules

r_binary_packages:
    - testthat

script: make test

This fails with the following error:

The command "Rscript -e 'deps <- devtools::install_deps(dependencies = TRUE);if (!all(deps %in% installed.packages())) { message("missing: ", paste(setdiff(deps, installed.packages()), collapse=", ")); q(status = 1, save = "no")}'" failed and exited with 1 during .

This makes sense: devtools::install_deps only works in the context of a package.

I’ve tried suppressing the installation step, by adding install: true to my configuration. However, now the dependencies are no longer installed, and the build consequently fails with

Error in loadNamespace(name) : there is no package called ‘modules’

2 Answers 2

Reset to default

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

4

It turns out that a naïve approach is fairly easy; the following (complete .travis.yml) works for my purposes:

language: R

install:
    - Rscript -e 'install.packages(c("devtools", "testthat"))'
    - Rscript -e 'devtools::install_github("klmr/modules")'

script: make test

However, I’d still prefer a solution that can actually use the Travis declarations (r_binary_packages, etc.) instead of having to install dependencies manually.

2

I was looking for an even more basic setup to get started. Here is what worked well for me.

  • .travis.yml:

    language: r
    
    install:
        - Rscript install_packages.R
    
    script:
        - Rscript testthat.R
    
  • install_packages.R:

    install.packages('testthat')
    
  • testthat.R:

    library(testthat)
    
    test_that('blabla', {
      expect_equal(1+2, 3)
    })
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.