Rstan/rstantools/travis


#1

Hi all -

For anyone who is writing R packages with rstantools, the following travis.yml seems to work fine for Travis CI:

language: r
sudo: true
cache: packages


matrix:
  include:
    - os: linux
      dist: trusty
      r: release
      r_binary_packages:
        - devtools
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-7
      env:
        - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
    - os: linux
      dist: trusty
      r: devel
      r_binary_packages:
        - devtools
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-7
      env:
        - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
    - os: osx
      fortran: false
      osx_image: xcode10
      r: release

     
before_install:
  - mkdir -p ~/.R/
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo "CXX14 = g++-7 -fPIC" >> ~/.R/Makevars; fi
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo "CXX14FLAGS = -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -Wno-unused-local-typedefs -Wno-ignored-attributes -Wno-deprecated-declarations -Wno-attributes -O3" >> ~/.R/Makevars; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then echo "CXX14 = clang++ -arch x86_64 -ftemplate-depth-256" >> ~/.R/Makevars; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then echo "CXX14FLAGS = -O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function  -Wno-unknown-pragmas" >> ~/.R/Makevars; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then echo "CC = clang" >> ~/.R/Makevars; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sudo tlmgr install inconsolata; fi

I’m not saying this travis file is optimal, but it works even with installing Rstan 2.18.1 from source on Travis.


#2

Thanks. I don’t think the -Wno-macro-redefined is needed in the post-2.17.x era.


#3

Also, that should be CXX14FLAGS and you may want to add a few things to it, as in

"CXX14FLAGS = -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -Wno-unused-local-typedefs -Wno-ignored-attributes -Wno-deprecated-declarations -Wno-attributes -O3" >> ~/.R/Makevars

How to update a package that has StanHeaders and rstan in its LinkingTo
#4

Thanks for the fixes!


#5

I updated the above to include Mac OS X which Travis CI now supports. This .travis.yml file will compile your package on R devel and release on ubuntu/trusty and R release on Mac OS X (devel not currently supported).


#6

I had a failure using clang on ubuntu that I wanted to check with Travis, the following passes on travis and osx but fails for gcc – can anyone suggest how it might be modified so that the line near the bottom involving fPIC works for both gcc and clang?

language: r
sudo: false
cache: packages
  
r_check_args: "--no-vignettes"
r_build_args: '--no-build-vignettes'

matrix:
  include:
    - os: linux
      dist: trusty
      r: release
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-7
      env:
        - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
    - os: linux
      dist: trusty
      r: devel
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
          packages:
            - g++-7
      env:
        - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
        
    - os: linux
      dist: trusty
      r: release
      addons:
        apt:
          sources:
            - ubuntu-toolchain-r-test
            - sourceline: 'deb https://apt.llvm.org/trusty/ llvm-toolchain-trusty-7 main'
              key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
          packages:
            - clang-7
      env:
        - MATRIX_EVAL="CC=clang-7 CXX=clang++-7"
    - os: osx
      osx_image: xcode10
      r: release
      fortran: false

     
before_install:
  - mkdir -p ~/.R/
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo "CXX14 = clang++-7 -fPIC" >> ~/.R/Makevars; fi
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo "CXX14FLAGS = -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -Wno-unused-local-typedefs -Wno-ignored-attributes -Wno-deprecated-declarations -Wno-attributes -O3" >> ~/.R/Makevars; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then echo "CXX14 = clang++ -arch x86_64 -ftemplate-depth-256" >> ~/.R/Makevars; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then echo "CXX14FLAGS = -O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function  -Wno-unknown-pragmas" >> ~/.R/Makevars; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then echo "CC = clang" >> ~/.R/Makevars; fi
  - eval "${MATRIX_EVAL}"

#7

Did you ever figure this out? Travis hasn’t given me a passing build since about October (I’m assuming because of 2.18, but I’m not sure – I just tried to add the above code to my existing .travis.yml, but it didn’t seem to fix the issue). I miss my green “passing” badge!


#8

I just updated the original post to my current Travis file (which runs fine). Let me know if that works.


#9

Siiiigh, it does not work for me: https://travis-ci.org/lcomm/rsemicompstan/builds/468718922. I wish I could remember why I had custom stuff in my .travis.yml, but I can’t bring myself to dig into it again.


#10

Not an R programmer, but you have ImportFrom in namespace but in the code base use package::func which means that ImportFrom is not needed or you should just use func.


#11

@ahartikainen, your comment helped me find one instance of a importFrom of a package I no longer wanted as a dependency, and made me stumble across this post I somehow missed: How to update a package that has StanHeaders and rstan in its LinkingTo. (I had been trying to avoid updating rstan while writing these papers, but I guess that ship sailed.) Thank you!

It still doesn’t pass on Travis, but it’s closer than it was.