06-Model AZMET data #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' This example runs an R script that errors when there are problems with the | |
#' data, causing the action to fail on GitHub. It is set to run when changes | |
#' are pushed to the main branch or when pull requests are made to the main | |
#' branch, but *only* if the data/ folder has changes. You can also run it with | |
#' a button on GitHub (`workflow_dispatch`). Compared to the simple | |
#' `hello_world.yaml` example, this handles installing R packages differently. | |
#' The required packages are in a renv.lock file created by the `renv` R package. | |
#' This workflow uses the setup-renv action to install those needed packages and | |
#' cache them so this step runs faster subsequent times. It also uses the `pak` | |
#' package as a back-end to do the actual installing. `pak` is able to deterine | |
#' any system libraries or command line tools an R package needs and installs | |
#' those as well. | |
on: | |
workflow_dispatch | |
name: Model AZMET data | |
jobs: | |
azmet: | |
strategy: | |
matrix: | |
station_id: [az01, az02, az04, az05, az06, az07, az08, az09, az12, az14, az15, az19, az20, az22, az23, az24, az26, az27, az28, az32, az33, az35, az36, az37, az38, az39, az40, az41, az42, az43, az44] | |
runs-on: ubuntu-latest | |
env: | |
RENV_CONFIG_PAK_ENABLED: TRUE #use the `pak` package for installing R packages—it automatically detects and install system dependencies on ubuntu | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup R | |
uses: r-lib/actions/setup-r@v2 | |
with: | |
r-version: "renv" #use the same version of R recorded in renv.lock | |
- name: Install R packages | |
uses: r-lib/actions/setup-renv@v2 #uses `renv::restore()` | |
- name: Run azmet.R | |
run: | | |
Rscript R/azmet.R | |
env: | |
AZMET_STATION: ${{ matrix.station_id }} #pass the station IDs defined in matrix: via an environment variable | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
path: output/* #upload everything in the output/ folder as an artifact | |
name: ${{ matrix.station_id }} #name it the station ID name | |
# a second job that combines the files generated by the jobs above | |
combine: | |
runs-on: ubuntu-latest | |
needs: azmet #requires that the 'azmet' job is completed | |
env: | |
RENV_CONFIG_PAK_ENABLED: TRUE #use the `pak` package for installing R packages—it automatically detects and install system dependencies on ubuntu | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup R | |
uses: r-lib/actions/setup-r@v2 | |
with: | |
r-version: "renv" #use the same version of R recorded in renv.lock | |
- name: Install R packages | |
uses: r-lib/actions/setup-renv@v2 #uses `renv::restore()` | |
- name: Download artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: output/ | |
merge-multiple: true #puts all of the artifacts in output/ rather than in subdirectories | |
- name: Combine model reports | |
run: Rscript R/combine.R | |
# Uploads combined report as an artifact | |
# Other options would be to commit this file (as in render_readme.yaml) | |
# or to use something like rclone to copy the output to a cloud drive. | |
# See https://github.com/marketplace/actions/setup-rclone-action and | |
# https://rclone.org/ for examples. | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
path: output/model_report.csv | |
name: model_report |