Skip to content

Run R Script

Run R Script #18

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.
# versiones predeterminadas.
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
shell: bash
run: |
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: Cache data files
uses: actions/cache/restore@v4
with:
path: |
demanda_diaria_Edesur.txt
demanda_diaria_GBA.txt
key: ${{ runner.os }}-data
# key: ${{ runner.os }}-data-${{ hashFiles('demanda_diaria_Edesur.txt', 'demanda_diaria_GBA.txt') }}
restore-keys: ${{ runner.os }}-data
- name: Run R script
run: |
Rscript demanda_diaria_API_MEM.R
- name: Cache updated data files
uses: actions/cache/save@v4
with:
path: |
demanda_diaria_Edesur.txt
demanda_diaria_GBA.txt
# key: ${{ runner.os }}-data-${{ hashFiles('demanda_diaria_Edesur.txt', 'demanda_diaria_GBA.txt') }}
key: ${{ runner.os }}-data
- name: Save plot
run: |
datetime=$(date -u +"%Y%m%dT%H%M%SZ")
mv demanda_diaria.svg demanda_diaria_${datetime}.svg
echo "datetime=${datetime}" >> $GITHUB_ENV
echo "Plot saved as demanda_diaria_${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