# Workflow

## *class* <mark style="color:purple;">Workflow</mark>

Workflows on Redivis are where analytical pipelines are built and executed. All workflows are owned by a user, and are made up of transforms, notebooks, and their output tables.

{% hint style="warning" %}
Workflows were previously referred to as "Projects" on Redivis. Existing code that utilized the "project" terminology will continue to work (e.g., `User$list_projects()`).&#x20;

However, we encourage users to migrate their code to prevent future issues and confusion.
{% endhint %}

## Constructors

<table><thead><tr><th width="370.3046875">Method</th><th>Description</th></tr></thead><tbody><tr><td><a href="redivis/redivisusdcurrent_workflow"><strong><code>redivis$current_workflow</code></strong></a>()</td><td>Get the current default workflow. Typically called within notebooks.</td></tr><tr><td><a href="organization/organizationusdlist_workflows"><strong><code>Organization$list_workflows</code></strong></a>([max_results])</td><td>List all workflows in the organization.</td></tr><tr><td><a href="user/userusdlist_workflows"><strong><code>User$list_workflows</code></strong></a>([max_results])</td><td>List all workflows owned by a user.</td></tr><tr><td><a href="organization/organizationusdworkflow"><strong><code>Organization$workflow</code></strong></a>(name)</td><td>Construct a new workflow instance that references a workflow owned by an organization.</td></tr><tr><td><a href="user/userusdworkflow"><strong><code>User$workflow</code></strong></a>(name)</td><td>Construct a new workflow instance that references a workflow owned by a user.</td></tr></tbody></table>

## Examples

{% tabs %}
{% tab title="Basics" %}

<pre class="language-r"><code class="lang-r">library("redivis")

workflow &#x3C;- redivis$user("imathews")$workflow("example_workflow_climate_analysis")
tables &#x3C;- workflow$list_tables()

for (table in tables){
<strong>    # Properties will be populated with the table.list resource representation
</strong>    print(table$properties) 
    
    table$get()
    # Properties will now be populated with the table.get resource representation
    print(table$properties) 
}

workflow$table("join_lat_lon_output")$exists() # -> TRUE
</code></pre>

{% endtab %}

{% tab title="Scoped queries" %}

```r
library("redivis")

workflow <- redivis$user("imathews")$workflow("example_workflow_climate_analysis")

query = workflow$query("
    SELECT
        id,
        EXTRACT(YEAR FROM date) AS year,
        SUM(value) AS annual_precip
    FROM daily_observations
    WHERE (element = 'PRCP')
    GROUP BY id, year
")

query$to_tibble()
# 	id	        year	    annual_precip
# 0	CA0023026HN	2003	    2925.0
# ...
```

{% endtab %}
{% endtabs %}

## Fields

| **`properties`**          | <p>A named list containing the <a href="../../../resource-definitions/workflow">API resource representation of the workflow</a>. <br><br>This will be fully populated after calling <a href="workflow/workflowusdget">Workflow$get()</a>, and partially populated for worfklows created via <a href="user/userusdlist_workflows">User$list\_workflows</a>. Otherwise will be <code>NULL</code>.</p> |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`qualified_reference`** | The [fully qualified reference](https://docs.redivis.com/api/referencing-resources) for the workflow, which can be used in SQL queries or the REST API. E.g., `imathews.example_workflow_climate_analysis:x7kh`                                                                                                                                                                                     |
| **`organization`**        | A reference to the [Organization](https://docs.redivis.com/api/client-libraries/redivis-r/reference/organization) instance that constructed this workflow.                                                                                                                                                                                                                                          |
| **`scoped_reference`**    | The canonical reference for the workflow, without the username qualifier. E.g.,: `example_workflow_climate_analysis:x7kh`                                                                                                                                                                                                                                                                           |
| **`user`**                | A reference to the [User](https://docs.redivis.com/api/client-libraries/redivis-r/reference/user) instance that constructed this workflow.                                                                                                                                                                                                                                                          |

## Methods

<table data-header-hidden><thead><tr><th width="441"></th><th></th></tr></thead><tbody><tr><td><a href="workflow/workflowusdconnect_dbi"><strong><code>Workflow$connect_dbi</code></strong></a>()</td><td>Create a DBI connection scoped to the workflow.</td></tr><tr><td><a href="workflow/workflowusddatasource"><strong><code>Workflow$datasource</code></strong></a>()</td><td>Create a reference to a datasource within the workflow.</td></tr><tr><td><a href="workflow/workflowusdexists"><strong><code>Workflow$exists</code></strong></a>()</td><td>Check whether the workflow exists.</td></tr><tr><td><a href="workflow/workflowusdget"><strong><code>Workflow$get</code></strong></a>()</td><td>Get the workflow, populating the <code>properties</code> attribute on the current instance.</td></tr><tr><td><a href="workflow/workflowusdlist_datasources"><strong><code>Workflow$list_datasources</code></strong></a>([max_results])</td><td>List all datasources in the workflow.</td></tr><tr><td><a href="workflow/workflowusdlist_notebooks"><strong><code>Workflow$list_notebooks</code></strong></a>([max_results])</td><td>List all notebooks in the workflow.</td></tr><tr><td><a href="workflow/workflowusdlist_parameters"><strong><code>Workflow$list_parameters</code></strong></a>([max_results])</td><td>List all parameters in the workflow.</td></tr><tr><td><a href="workflow/workflowusdlist_tables"><strong><code>Workflow$list_tables</code></strong></a>([max_results])</td><td>List all tables in the workflow.</td></tr><tr><td><a href="workflow/workflowusdlist_transforms"><strong><code>Workflow$list_transforms</code></strong></a>([max_results])</td><td>List all transforms in the workflow.</td></tr><tr><td><a href="workflow/workflowusdnotebook"><strong><code>Workflow$notebook</code></strong></a>(name)</td><td>Create a reference to a specific notebook within the workflow.</td></tr><tr><td><a href="workflow/workflowusdparameter"><strong><code>Workflow$parameter</code></strong></a>(name)</td><td>Create a reference to a specific parameter within the workflow.</td></tr><tr><td><a href="workflow/workflowusdquery"><strong><code>Workflow$query</code></strong></a>(query_string)</td><td>Create a query scoped to the workflow.</td></tr><tr><td><a href="workflow/workflowusdtable"><strong><code>Workflow$table</code></strong></a>(table_reference)</td><td>Create a reference to a specific table within the workflow.</td></tr><tr><td><a href="workflow/workflowusdtransform"><strong><code>Workflow$transform</code></strong></a>(name)</td><td>Create a reference to a specific transform within the workflow.</td></tr><tr><td><a href="workflow/workflowusdupdate_variables"><strong><code>Workflow$update_variables</code></strong></a>(variables)</td><td>Bulk update variable metadata across tables in a workflow.</td></tr></tbody></table>
