Site icon R-bloggers

Github Actions with R

[This article was first published on shikokuchuo{net}, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

                                                            sha256
1 6f5b37d9b73dcd70f3c8b68eabbe00c4a709f2a3e694d964121af145105f1655
< aside> Shikokuchuo

Github Actions with R

Set up a cron job to run your R scripts at specified times.

Enabled with a simple yaml configuration file.

Save the following as main.yml in .github/workflows of your Github repository:

name: Raction
on:
  schedule:
    - cron: '30 22 * * 1-5'
jobs:
  render:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up R
        uses: r-lib/actions/setup-r@v1
      - name: Install dependencies
        run: |
          install.packages(c("magrittr", "purrr"), type = "win.binary")
        shell: Rscript {0}
      - name: Script
        run: Rscript nameofscript.R
      - name: Commit files
        run: |
          git config --local user.name github-actions
          git config --local user.email "actions@github.com"
          git add output/*
          git commit -am "commit on $(date)"
          git push origin main
        env:
          REPO_KEY: ${{secrets.GITHUB_TOKEN}}
          username: github-actions
< aside>
  1. This example cron job runs every Mon-Fri at 22.30.

  2. Customize your R packages to install.

  3. Make sure to change nameofscript.R to your actual script name.

  4. Assumes your script writes files to the ‘output’ directory, change if necessary.

  5. Assumes your repository branch is ‘main’, change if necessary.

  6. Note that this script is run on a Windows VM using Windows R binary packages. This is currently much faster than building a lot of dependencies on Linux (which is also prone to failure).

Reference

The Github Actions with R reference:
https://orchid00.github.io/actions_sandbox/

To leave a comment for the author, please follow the link and comment on their blog: shikokuchuo{net}.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.