making awesome automations with Github Actions

Beatriz Milz

rstudio::conf 2022 | July 2022

Slides: beatrizmilz.github.io/rstudioconf2022

Run scripts… 🙋‍♀️️

every day?


every week?


every month?

What is GitHub Actions?


How can we run R Scripts with it?

R packages 📦


# Load usethis
library(usethis)
# run check
use_github_action("check-standard")
# build pkgdown site
use_github_action("pkgdown")


See other examples in: github.com/r-lib/actions/

How important is GHA to RStudio?


This image is a line plot made with ggplot2, it shows  GitHub Actions runs by RStudio's organization on GitHub. In the X axis, we have month/year and in the Y axis we have the total GitHub Actions runs per month. We can see that the Actions runs increased from 4k per month in May/2020 to around 18k per month in May/2022.

What else can we do?

Run arbitrary R scripts

  • Scrape data from the internet

  • Run reports with RMarkdown or Quarto

  • Send emails

  • Save results

on: # what triggers the workflow?
  workflow_dispatch: # start when pressing a button
  schedule: 
  - cron: "0 0 * * *" # run everyday

name: execute-r-script # name of the workflow

jobs: # what the workflow should do?
  execute-r-script:
    runs-on: ubuntu-latest # Run on Ubuntu
    steps:
      - uses: actions/checkout@v3
      - uses: r-lib/actions/setup-r@v2 # Install R
        with: 
          use-public-rspm: true    
      - name: run-script
        run: Rscript my_awesome_R_script.R  # Run R script

on: # what triggers the workflow?
  workflow_dispatch: # start when pressing a button
  schedule: 
  - cron: "0 0 * * *" # run everyday

name: execute-r-script # name of the workflow

jobs: # what the workflow should do?
  execute-r-script:
    runs-on: ubuntu-latest # Run on Ubuntu
    steps:
      - uses: actions/checkout@v3
      - uses: r-lib/actions/setup-r@v2 # Install R
        with: 
          use-public-rspm: true    
      - name: run-script
        run: Rscript my_awesome_R_script.R  # Run R script

on: # what triggers the workflow?
  workflow_dispatch: # start when pressing a button
  schedule: 
  - cron: "0 0 * * *" # run everyday

name: execute-r-script # name of the workflow

jobs: # what the workflow should do?
  execute-r-script:
    runs-on: ubuntu-latest # Run on Ubuntu
    steps:
      - uses: actions/checkout@v3
      - uses: r-lib/actions/setup-r@v2 # Install R
        with: 
          use-public-rspm: true    
      - name: run-script
        run: Rscript my_awesome_R_script.R  # Run R script

More examples…

https://beamilz.com/series-gha.html

Thanks!

Beatriz Milz 🇧🇷

  • Contact

  • About Bea

    • R-Ladies São Paulo Co-organizer

    • Teacher at Curso-R

    • Tidyverse instructor certified by RStudio