An Airflow operator for executing an R script within an renv project.
Suppose you have an renv project directory like the following:
/home/airflow-user/airflow/dags/renv-example
├── .Rprofile
├── renv
│ ├── .gitignore
│ ├── activate.R
│ ├── library
│ ├── local
│ └── settings.dcf
├── renv.lock
└── script.R
To configure an Airflow task that activates the renv project and executes script.R
, use RenvOperator
like so:
from datetime import datetime, timedelta
from airflow import DAG
from airflow_renv_operator import RenvOperator
dag = DAG(
dag_id='renv-example-dag',
schedule_interval=timedelta(days=1),
start_date=datetime(2021, 1, 1),
catchup=False,
)
task = RenvOperator(
task_id='renv-example-task',
project_path='/home/airflow-user/airflow/dags/renv-example',
script_path='/home/airflow-user/airflow/dags/renv-example/script.R',
dag=dag
)
To initialize RenvOperator
, you must supply values for task_id
and the following required parameters:
project_path
: A string orpathlib.Path
object representing the path to your renv project directory.script_path
: A string orpathlib.Path
object representing the absolute or relative path to an R script that can be executed within your renv project. Ifscript_path
is relative, it will be resolved fromproject_path
.
Additional parameters accepted by Airflow's BaseOperator
may be passed as keyword arguments.
Execute tests with Pytest:
pytest