Skip to content

Run R Script

Run R Script #20

Workflow file for this run

name: Run R Script
on:
schedule:
- cron: '0 0 * * *' # Runs daily at midnight
workflow_dispatch:
jobs:
run-r-script:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
# Esta acción también descarga demanda_diaria_GBA.txt y demanda_diaria_Edesur.txt del repo.
uses: actions/checkout@v3
- name: Install deps
run: sudo apt-get install libcurl4-openssl-dev
- name: Set up R
uses: r-lib/actions/setup-r@v2
with:
r-version: '4.1.0' # Specify the R version you need
- name: Set RENV_PATHS_ROOT and datetime
shell: bash
run: |
datetime=$(date -u +"%Y%m%dT%H%M%SZ")
echo "datetime=${datetime}" >> $GITHUB_ENV
echo "RENV_PATHS_ROOT=${{ runner.temp }}/renv" >> $GITHUB_ENV
- name: Install and activate renv
run: |
install.packages("renv")
renv::activate()
shell: Rscript {0}
- name: Get R and OS version
run: |
cat(sprintf("OS_VERSION=%s\n", sessionInfo()$running), append=TRUE, file=Sys.getenv("GITHUB_ENV"));
cat(sprintf("R_VERSION=%s\n", R.Version()$version.string), append=TRUE, file=Sys.getenv("GITHUB_ENV"));
shell: Rscript {0}
- name: Restore Renv package cache
uses: actions/cache@v4
with:
path: ${{ env.RENV_PATHS_ROOT }}
key: ${{ env.OS_VERSION }}-${{ env.R_VERSION }}-${{ inputs.cache-version }}-${{ hashFiles('renv.lock') }}
restore-keys: ${{ env.OS_VERSION }}-${{ env.R_VERSION }}-${{ inputs.cache-version }}-
- name: Install R packages (or pull from cache)
run: install.packages(c("httr", "ggplot2", "jsonlite", "data.table"));
shell: Rscript {0}
- name: Run R script
run: |
Rscript demanda_diaria_API_MEM.R
- name: commit updated data files
run: |
git add demanda_diaria_Edesur.txt demanda_diaria_GBA.txt
git commit -m 'Actions run_id=${{ github.run_id }}, dt=${{ env.datetime }}'
- name: Save plot
run: |
mv demanda_diaria.svg demanda_diaria_${{ env.datetime }}.svg
echo "Plot saved as demanda_diaria_${{ env.datetime }}.svg"
- name: Upload plot as artifact
uses: actions/upload-artifact@v4
with:
name: ${{ github.run_id }}_demanda_diaria_${{ env.datetime }}
path: demanda_diaria_${{ env.datetime }}.svg