# Posit Workbench (RStudio)

## Introduction

The Posit Workbench (RStudio) app runs on the DNAnexus Platform. You can use RStudio to run analysis workflows, inspect data, and work in an interactive cloud terminal.

## Prerequisites and Availability

Posit Workbench on the DNAnexus Platform is available for organizations that have an existing license agreement with Posit. Before you can launch an RStudio session, you need to [request access for your organization](#request-access-for-your-organization).

You do not need to provide a license key. DNAnexus verifies your organization's eligibility directly with Posit during setup.

### Request Access for Your Organization

Requesting access to Posit Workbench (RStudio) for your organization is a one-time process that requires coordination between your organization, Posit, and DNAnexus.

1. Include the following details in your access request:
   * Customer legal entity name: Provide the name that appears in your Posit contract.
   * Organization ID: Provide the org ID, for example `org-abcgenomics`.
   * Seat admin name: Identify the person who [manages seats](#seat-management) for Posit Workbench in DNAnexus.
   * Seat admin email: Provide the seat admin's email address.
   * Seat admin DNAnexus username: Provide the seat admin's active DNAnexus account, for example, `user-johndoe`.
   * Approximate number of expected users: This helps Posit validate seat allocation for your organization.
2. Send an access request to [DNAnexus Support](mailto:support@dnanexus.com) and include all required information.
3. Wait for DNAnexus to verify eligibility with Posit and enable access for your organization.

### Seat Management

Seat limits are enforced at the organization level by the org admin.

* Org admins can review member limits on the [organization member guide](/user/organization-member-guide.md).
* When the member limit is reached, inviting new members is automatically disabled.
* If a user is removed from the licensing organization, active Posit Workbench sessions for that user are terminated and the seat is freed.

You can also review the seat limit with the organization describe command:

```shell
dx org describe org-abcgenomics
```

In the command output, the `memberLimit` field reports the maximum number of members allowed for the organization.

For support with licensing or access, [contact DNAnexus Support](mailto:support@dnanexus.com).

## Starting a Session

To create a new workbench environment:

1. In the **DNAnexus Platform** > **Tools**, select **Posit Workbench (RStudio)**.
2. On the Sessions page, click **New Workbench**.
3. (Optional) Enter an environment name.
4. Select an [instance type](/developer/api/running-analyses/instance-types.md).
5. Keep **High** priority unless you have a specific reason to change it.
6. Click **Start Environment**.

Wait until status changes from **Initializing** to **Ready**, so you can:

* Launch the Posit Workbench by selecting the session name or clicking **Open**.
* View details, such as estimated price, by opening the **Info Panel** icon next to **New Workbench**.

## Use the RStudio Environment

### Transfer Files with the Terminal

The Terminal tab supports DNAnexus CLI commands for file movement between your project and your active workbench environment.

#### Upload Results from RStudio to a Project

1. Open the Terminal tab in RStudio.
2. Upload a file:

   ```shell
   # For help, see dx upload -h
   dx upload <local_file>
   ```
3. Repeat the command for additional files or provide a directory path.

You can upload multiple files or a full directory in one command.

#### Download Project Files to RStudio

1. Open the Terminal tab in RStudio.
2. List project contents:

   ```shell
   dx ls
   ```
3. Download one or more files or folders:

   ```shell
   # The download target can be a file name or a file ID.
   # For help, see dx download -h
   dx download <dnanexus_platform_file>
   ```

Downloaded files are placed in your current working directory.

The app has VIEW access to projects you can access and CONTRIBUTE access to the project where the app is running.

![The RStudio Terminal runs dx download commands to copy project data into your workbench workspace.](/files/50MUsIb0B3O7rBPyD5mZ)

#### Import Tabular Data into R

After you download CSV or TSV files into your workbench directory, import them in R with standard read functions.

![After downloading a CSV file with dx download, use a base R import function in RStudio to load the file into your analysis session.](/files/N0KOFIxon9exSZ0mRmf8)

#### Read Large Files from `/mnt/project`

The project where RStudio is running is mounted as read-only at `/mnt/project`. Use the mount path when you need read-only access and you do not want to copy large files into local workspace storage.

1. Confirm that your session is running in the target project.
2. Open files from `/mnt/project` in your R scripts.
3. Read only the data ranges you need.

This method reduces local disk usage and can increase API traffic.

### Install System Packages

Run package installation commands in the Terminal tab with `sudo`.

For example, to install `wget`:

```shell
# Refresh package indexes so apt can find current package metadata before install.
sudo apt-get update && sudo apt-get install wget
```

![The Terminal supports apt-get commands so you can install required system packages with sudo access.](/files/dN8EkuaLlBCttVDNFJui)

{% hint style="info" %}
The workbench environment is temporary. Files and package installations in the worker are removed when the session ends. Upload files you want to keep to your DNAnexus project.
{% endhint %}

## Save and Restore Workspace Data

Use project uploads for individual outputs. Use folder backups when you want a single archive of a working directory.

### Back Up a Folder to Your Project

To back up the current folder with default settings:

```shell
# For help, see dx-backup-folder -h
dx-backup-folder
```

By default, the backup file name is `.Backups/<rstudio_workbench>.<dnanexus-username>.tar.gz`.

To back up a specific folder to a specific destination path:

```shell
dx-backup-folder -d /.Backups/workspace1.tar.gz workspace/
```

To exclude paths or patterns:

```shell
# --exclude and --exclude-from follow GNU tar pattern behavior.
dx-backup-folder --exclude 'R' --exclude '*/.RData' -d /small_backup/
```

### Restore a Folder from a Backup

To restore into the current directory without overwriting local files:

```shell
# Add --overwrite to replace local files.
# Use --output <local_folder> to restore into a specific folder.
# For help, see dx-restore-folder -h
dx-restore-folder /.Backups/rstudio_workbench.testuser.2022-03-14T20-47-03.tar.gz
```

## Terminating a Session

You can terminate a session from either of these locations:

* In the active RStudio environment header, select **Terminate**.
* In the Sessions page, open the three-dot menu for a running session and select **End environment**.

![The Sessions page shows the row action menu where you can select End Environment to stop a running session.](/files/0pAfIJejlsrnCHIGaBLm)

{% hint style="info" %}
Closing the browser does not stop a running session. Compute charges continue until you terminate the environment.

If the job is still running, you can return to the same environment by opening the session URL `job-xxxx.dnanexus.cloud`.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.dnanexus.com/user/rstudio.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
