

# RStudio on Amazon SageMaker AI user guide


With RStudio support in Amazon SageMaker AI, you can put your production workflows in place and take advantage of SageMaker AI features. The following topics show how to launch an RStudio session and complete key workflows. For information about managing RStudio on SageMaker AI, see [RStudio on Amazon SageMaker AI management](rstudio-manage.md). 

For information about the onboarding steps to create an Amazon SageMaker AI domain with RStudio enabled, see [Amazon SageMaker AI domain overview](gs-studio-onboard.md).  

For information about the AWS Regions that RStudio on SageMaker AI is supported in, see [Supported Regions and Quotas](regions-quotas.md).  

**Topics**
+ [

## Collaborate in RStudio
](#rstudio-collaborate)
+ [

## Base R image
](#rstudio-base-image)
+ [

## RSession application colocation
](#rstudio-colocation)
+ [

# Launch RSessions from the RStudio Launcher
](rstudio-launcher.md)
+ [

# Suspend your RSessions
](rstudio-launcher-suspend.md)
+ [

# Delete your RSessions
](rstudio-launcher-delete.md)
+ [

# RStudio Connect
](rstudio-connect.md)
+ [

# Amazon SageMaker AI feature integration with RStudio on Amazon SageMaker AI
](rstudio-sm-features.md)

## Collaborate in RStudio


 To share your RStudio project, you can connect RStudio to your Git repo. For information on setting this up, see [ Version Control with Git and SVN](https://support.rstudio.com/hc/en-us/articles/200532077-Version-Control-with-Git-and-SVN). 

 Note: Project sharing and realtime collaboration are not currently supported when using RStudio on Amazon SageMaker AI.  

## Base R image


 When launching your RStudio instance, the Base R image serves as the basis of your instance. This image extends the [r-session-complete](https://hub.docker.com/r/rstudio/r-session-complete) Docker image.  

 This Base R image includes the following: 
+  R v4.0 or higher
+  `awscli`, `sagemaker`, and `boto3` Python packages 
+  [Reticulate](https://rstudio.github.io/reticulate/) package for R SDK integration 

## RSession application colocation


Users can create multiple RSession applications on the same instance. Each instance type supports up to four colocated RSession applications. This applies to each user independently. For example, if two users create applications, then SageMaker AI allocates different underlying instances to each user. Each of these instances would support 4 RSession applications.

Customers only pay for the instance type used regardless of how many Rsession applications are running on the instance. If a user creates an RSession with a different associated instance type, then a new underlying instance is created.

# Launch RSessions from the RStudio Launcher


**Important**  
Custom IAM policies that allow Amazon SageMaker Studio or Amazon SageMaker Studio Classic to create Amazon SageMaker resources must also grant permissions to add tags to those resources. The permission to add tags to resources is required because Studio and Studio Classic automatically tag any resources they create. If an IAM policy allows Studio and Studio Classic to create resources but does not allow tagging, "AccessDenied" errors can occur when trying to create resources. For more information, see [Provide permissions for tagging SageMaker AI resources](security_iam_id-based-policy-examples.md#grant-tagging-permissions).  
[AWS managed policies for Amazon SageMaker AI](security-iam-awsmanpol.md) that give permissions to create SageMaker resources already include permissions to add tags while creating those resources.

 The following sections show how to use the RStudio Launcher to launch RSessions. They also include information about how to open the RStudio Launcher when using RStudio on Amazon SageMaker AI.

## Open RStudio Launcher


Open the RStudio launcher using the following set of procedures that matches your environment.

### Open RStudio Launcher from the Amazon SageMaker AI Console


1. Open the Amazon SageMaker AI console at [https://console.aws.amazon.com/sagemaker/](https://console.aws.amazon.com/sagemaker/).

1.  From the left navigation, select **RStudio**.

1.  Under **Get Started**, select the domain and user profile to launch.

1.  Choose **Launch RStudio**.

### Open RStudio Launcher from Amazon SageMaker Studio


1. Navigate to Studio following the steps in [Launch Amazon SageMaker Studio](studio-updated-launch.md).

1. Under **Applications**, select **RStudio**.

1. From the RStudio landing page, choose **Launch application**.

### Open RStudio Launcher from the AWS CLI


The procedure to open the RStudio Launcher using the AWS CLI differs depending on the method used to manage your users. 

 **IAM Identity Center** 

1.  Use the AWS access portal to open your Amazon SageMaker AI domain. 

1.  Modify the URL path to “/rstudio/default” as follows. 

   ```
   #Studio URL
   https://<domain-id>.studio.<region>.sagemaker.aws/jupyter/default/lab
   
   #modified URL
   https://<domain-id>.studio.<region>.sagemaker.aws/rstudio/default
   ```

 **IAM** 

 To open the RStudio Launcher from the AWS CLI in IAM mode, complete the following procedure. 

1.  Create a presigned URL using the following command. 

   ```
   aws sagemaker create-presigned-domain-url --region <REGION> \
       --domain-id <DOMAIN-ID> \
       --user-profile-name <USER-PROFILE-NAME>
   ```

1.  Append *&redirect=RStudioServerPro* to the generated URL. 

1.  Navigate to the updated URL. 

## Launch RSessions


 After you’ve launched the RStudio Launcher, you can create a new RSession. 

1.  Select **New Session**. 

1.  Enter a **Session Name**. 

1.  Select an instance type that your RSession runs on. This defaults to `ml.t3.medium`.

1.  Select an Image that your RSession uses as the kernel. 

1.  Select Start Session. 

1.  After your session has been created, you can start it by selecting the name.  
**Note**  
If you receive a warning that there is a version mismatch between your RSession and RStudioServerPro apps, then you must upgrade the version of your RStudioServerPro app. For more information, see [RStudio Versioning](rstudio-version.md).

# Suspend your RSessions


The following procedure demonstrates how to suspend an RSession from the RStudio Launcher when using RStudio on Amazon SageMaker AI. For information about accessing the RStudio Launcher, see [Launch RSessions from the RStudio Launcher](rstudio-launcher.md).

1. From the RStudio Launcher, identify the RSession that you want to suspend. 

1. Select **Suspend** for the session. 

# Delete your RSessions


The following procedure demonstrates how to delete an RSession from the RStudio Launcher when using RStudio on Amazon SageMaker AI. For information about accessing the RStudio Launcher, see [Launch RSessions from the RStudio Launcher](rstudio-launcher.md).

1. From the RStudio Launcher, identify the RSession that you want to delete. 

1. Select **Quit** for the session. This opens a new **Quit Session** window. 

1. From the **Quit Session** window, select **Force Quit**, to end all child processes in the session.

1. Select **Quit Session** to confirm deletion of the session.

# RStudio Connect


 RStudio Connect enables data scientists to publish insights, dashboard and web applications from RStudio on Amazon SageMaker AI. For more information, see [Host RStudio Connect and Package Manager for ML development in RStudio on Amazon SageMaker AI](https://aws.amazon.com/blogs/machine-learning/host-rstudio-connect-and-package-manager-for-ml-development-in-rstudio-on-amazon-sagemaker/).

 For more information on RStudio Connect, see the [RStudio Connect User Guide](https://docs.rstudio.com/connect/user/). 

# Amazon SageMaker AI feature integration with RStudio on Amazon SageMaker AI


 One of the benefits of using RStudio on Amazon SageMaker AI is the integration of Amazon SageMaker AI features. This includes integration with Amazon SageMaker Studio Classic and Reticulate. The following gives information about these integrations and examples for using them.

 **Use Amazon SageMaker Studio Classic and RStudio on Amazon SageMaker AI** 

 Your Amazon SageMaker Studio Classic and RStudio instances share the same Amazon EFS file system. This means that files that you import and create using Studio Classic can be accessed using RStudio and vice versa. This allows you to work on the same files using both Studio Classic and RStudio without having to move your files between the two. For more information on this workflow, see the [Announcing Fully Managed RStudio on Amazon SageMaker AI for Data Scientists](https://aws.amazon.com/blogs/aws/announcing-fully-managed-rstudio-on-amazon-sagemaker-for-data-scientists) blog.

 **Use Amazon SageMaker SDK with reticulate** 

The [reticulate](https://rstudio.github.io/reticulate) package is used as an R interface to [Amazon SageMaker Python SDK](https://sagemaker.readthedocs.io/en/stable/) to make API calls to Amazon SageMaker. The reticulate package translates between R and Python objects, and Amazon SageMaker AI provides a serverless data science environment to train and deploy Machine Learning (ML) models at scale. For general information about the reticulate package, see [ R Interface to Python](https://rstudio.github.io/reticulate/).

For a blog that outlines how to use the reticulate package with Amazon SageMaker AI, see [Using R with Amazon SageMaker AI](https://aws.amazon.com/blogs/machine-learning/using-r-with-amazon-sagemaker/).

The following examples show how to use reticulate for specific use cases.
+ For a notebook that describes how to use reticulate to do batch transform to make predictions, see [Batch Transform Using R with Amazon SageMaker AI](https://sagemaker-examples.readthedocs.io/en/latest/r_examples/r_batch_transform/r_xgboost_batch_transform.html).
+ For a notebook that describes how to use reticulate to conduct hyperparameter tuning and generate predictions, see [Hyperparameter Optimization Using R with Amazon SageMaker AI](https://sagemaker-examples.readthedocs.io/en/latest/r_examples/r_xgboost_hpo_batch_transform/r_xgboost_hpo_batch_transform.html).