Docker, GitLab CI and Developing R Packages
When I started developing R packages, I did not care much whether they would build with no errors, no warnings and no notes. I hardly knew about Build & Reload
and Check
in RStudio. I am not going to lie. I never finished reading Hadley Wickham's R Packages book (I am sorry Hadley)! Then, I learned about including unit tests and data, correctly referencing external packages and such. When my first build happened with no errors, no warnings and no notes, I felt good.
That moment when your package passes checks with 0 errors, 0 warnings and 0 notes 💪 #rstats pic.twitter.com/b27r9JGJfX
— Mustafa Hasanbulli (@hasanbulli) September 7, 2017
Next step was to make this even fancier using GitLab CI to check and build my packages automatically every time I push a new commit to the development/master branch. I set up a GitLab runner on my machine but failed to correctly create a .gitlab-ci.yml
configuration file for the runner. Most blog posts suggested having a .yml
file that looked like
image: rocker/rstudio
test:
script:
- R -e 'install.packages(c(<list_of_packages_you_need>))'
- 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()'
But there is an easier way of doing this. Much shorter and cleaner. devtools
package provides an efficient way of building and testing packages. Your .gitlab-ci.yml
can look as simple as this
TSForecasteR-CI:
stage: test
image: rocker/tidyverse
script:
- R -e 'install.packages(c(<list_of_packages_you_need>))'
- R -e 'devtools::check()'
tags:
- r-packages
Here I am using the rocker/tidyverse
Docker image because it comes devtools
installed. This is all you need!