Chapter 11 GitLab

11.1 GitLab Continuous Integration

This is a generic template for R Markdown projcts. It does the following:

  1. Download and initialize the “r-base” Docker package;
  2. Update all installed software;
  3. Download the PanDoc software;
  4. In R, install the packges here, fs, and rmarkdown (as well as their dependencies);
  5. Create a “public” directory;
  6. Identify the most recently modified R Markdown file in the “scripts” directory;
  7. Use the rmarkdown R package to render that most recently modified file to an HTML file called index.html in the “public” directory.

GitLab Pages automatically becomes available if a Continuous Integration stage called “pages” leaves artifacts in the “public” directory. Therefore, this CI configuration basically means that the most recent version of a project’s R Markdown file becomes available at the GitLab Pages URL correspondig to that project’s repository.

Note that you will often want to use other packages in your scripts, and it’s worthwhile to install those in the before_script section. Therefore, you may want to add more lines to that section. For example, this line installs the remotes package, that allows you to install packages directly from their git repositories:

  - R -e "install.packages('remotes', repos='')"

In case you want to then install a package directly from a git repository using the remotes package, you can also add something like:

  - R -e "remotes::install_gitlab('r-packages/ufs');"

By adding those commands to the CI configuration in the section that already install the here, fs, and rmarkdown packages, these additional packages will also be available when the R Markdown script in rendered in the pages section.