Example gitlab-ci.yml for R Projects

Most people are running open source projects, so they can easily use github and travis for free. I don’t have that luxury, but gitlab has really caught my attention lately. Combining gitlab, gitlab runner with docker makes things very straightforward. Here is an example .gitlab-ci.yml file that you would need to include in the base directory of your R project to have it run R CMD check and run testthat tests.

1
2
3
4
5
6
7
8
image: rocker/rstudio  
test:  
   script:
    - R -e 'install.packages(c("needed here"))'
    - R CMD build . --no-build-vignettes --no-manual
    - PKG_FILE_NAME=$(ls -1t *.tar.gz | head -n 1)
    - R CMD check "${PKG_FILE_NAME}" --no-build-vignettes --no-manual
    - R -e 'devtools::test()'