# redivis

## *package* <mark style="color:purple;">Redivis</mark>

The redivis package, available via `library("redivis")`. Through its various methods, you can create, update, query, and read from resources on Redivis.

{% hint style="info" %}
To avoid conflicts with other packages and base R function names, redivis's top level functions are hosted in the **`redivis`** namespace, and accessible via the **`redivis$`** prefix. This means that code written for Redivis in Python, R, and Javascript is quite similar.

\
Previous versions of redivis-r recommended accessing top-level methods via the `redivis::` syntax (e.g., `redivis::user()`). This syntax is deprecated, and we recommend migrating existing code to use the `$` syntax.
{% endhint %}

## Methods

<table data-header-hidden><thead><tr><th width="441"></th><th></th></tr></thead><tbody><tr><td><a href="redivis/redivisusdconnect_dbi"><strong><code>redivis$connect_dbi</code></strong></a>()</td><td>Construct a globally scoped DBI connection across Redivis.</td></tr><tr><td><a href="redivis/redivisusdcurrent_notebook"><strong><code>redivis$current_notebook</code></strong></a>()</td><td>Construct a reference to the current notebook. Can only be called within a Redivis notebook.</td></tr><tr><td><a href="redivis/redivisusdcurrent_user"><strong><code>redivis$current_user</code></strong></a>()</td><td>Construct a reference to the currently authenticated user.</td></tr><tr><td><a href="redivis/redivisusdcurrent_workflow"><strong><code>redivis$current_workflow</code></strong></a>()</td><td>Construct a reference to the current workflow. Can only be called within a Redivis notebook, or if a <a href="../../../redivis-python/reference#environment-variables">default workflow is set</a>.</td></tr><tr><td><a href="redivis/redivisusddatasource"><strong><code>redivis$datasource</code></strong></a>(source)</td><td>Construct a new <a href="datasource">Datasource</a> instance. Can only be called if a <a href="../../../redivis-python/reference#environment-variables">default workflow is set</a>. Otherwise, use the <a href="workflow/workflowusddatasource">workflow$datasource()</a> constructor.</td></tr><tr><td><a href="../../redivis-python/reference/redivis/redivis.make_api_request"><strong><code>redivis$make_api_request</code></strong></a>([method, path, query, ...])</td><td>Call the Redivis API directly, for advanced use cases.</td></tr><tr><td><a href="redivis/redivisusdnotebook"><strong><code>redivis$notebook</code></strong></a>(name)</td><td>Construct a new <a href="notebook">Notebook</a> instance.</td></tr><tr><td><a href="redivis/redivisusdparameter"><strong><code>redivis$parameter</code></strong></a>(name)</td><td>Construct a new <a href="parameter">Parameter</a> instance.</td></tr><tr><td><a href="redivis/redivisusdorganization"><strong><code>redivis$organization</code></strong></a>(name)</td><td>Construct a new <a href="organization">Organization</a> instance.</td></tr><tr><td><a href="redivis/redivisusdquery"><strong><code>redivis$query</code></strong></a>(query)</td><td>Execute a SQL query, returning a <a href="query">Query</a> instance.</td></tr><tr><td><a href="redivis/redivisusdtable"><strong><code>redivis$table</code></strong></a>(name)</td><td>Construct a new <a href="table">Table</a> instance. <br><br>This method can only be called if <a href="..#environment-variables">default workflow / dataset is set</a>  (this is automatically set within a Redivis notebook to that notebook's workflow).</td></tr><tr><td><a href="redivis/redivisusdtransform"><strong><code>redivis$transform</code></strong></a>(name)</td><td>Construct a new <a href="transform">Transform</a> instance.</td></tr><tr><td><a href="redivis/redivisusduser"><strong><code>redivis$user</code></strong></a>(name)</td><td>Construct a new <a href="user">User</a> instance.</td></tr></tbody></table>

## Examples

```r
devtools::install_github("redivis/redivis-r")
library("redivis")

organization <- redivis$organization("Demo")
# organization$list_datasets(), organization$dataset("Iris species"), etc...

dataset <- organization$dataset("iris_species")
table <- dataset$table("iris")  
# table$to_tibble(), etc...
# In a notebook, can do redivis$table("_source_") to reference the source table

query <- redivis$query("
    SELECT * 
    FROM demo.iris_species.iris 
    WHERE SepalLengthCm > 5
")
# query$to_tibble(), etc...
```
