All Products
Search
Document Center

Platform For AI:Install the R kernel in DSW

Last Updated:Jan 19, 2026

Data Science Workshop (DSW) of Platform for AI (PAI) integrates open source JupyterLab. You can install the R kernel on a DSW instance to run R scripts in notebooks for data analysis. This topic describes how to install the R kernel on a DSW instance.

Prerequisites

A DSW instance is created. For more information, see Create a DSW instance.

Procedure

  1. Go to the development environment of a DSW instance.

    1. Log on to the PAI console.

    2. In the left-side navigation pane, click Workspaces. On the Workspaces page, click the name of the workspace that you want to manage.

    3. In the upper-left corner of the page, select the region where you want to use PAI.

    4. In the left-side navigation pane, choose Model Training > Data Science Workshop (DSW).

    5. Optional: On the Data Science Workshop (DSW) page, enter the name of a DSW instance or a keyword in the search box to search for the DSW instance.

    6. Click Open in the Actions column of the instance.

  2. Perform the following steps in the terminal:

    1. Install the R language.

      Run the following command to install the R language from Ubuntu repositories by using the Advanced Packaging Tool (APT).

      If the Proceed ([y]/n) message appears during command execution, enter y and then press the Enter key.

      apt update
      apt install r-base
    2. Install IRkernel.

      IRkernel is an R kernel for Jupyter. To install IRkernel, enter R in the terminal, press the Enter key to start an R session, and then run the following command:

      install.packages('IRkernel')
      IRkernel::installspec()

      Exit the R session after IRkernel is installed.

      q()
  3. Refresh the web page that contains the Launcher tab and check whether the R kernel is installed.

    Open a new Launcher tab. If the R kernel is installed, options for an R notebook and console are available. Click R to create an R notebook and use R in JupyterLab.

    image

Example: Data analysis by using R

In this example, a built-in dataset in R named mtcars is used. To perform data analysis on the dataset, create an R notebook and run the following commands to load the built-in dataset, calculate the average horsepower (hp) of each car model, and plot the relationship between horsepower (hp) and miles per gallon (mpg) by using the ggplot2 package.

install.packages("ggplot2")
# Install the ggplot2 package.
library(ggplot2)

# Load the mtcars dataset.
data(mtcars)

# Print the first few rows of the mtcars dataset.
head(mtcars)

# Calculate the average horsepower (hp) of each car model.
average_hp_by_cyl <- aggregate(mtcars$hp, by=list(mtcars$cyl), FUN=mean)
colnames(average_hp_by_cyl) <- c("cylinders", "average_hp")

# Print the average horsepower (hp).
print(average_hp_by_cyl)

# Use ggplot2 to plot the relationship between horsepower (hp) and miles per gallon (mpg).
ggplot(mtcars, aes(x=mpg, y=hp)) +
geom_point() + # Plot points.
geom_smooth(method="lm") + # Plot a linear regression line.
labs(title="Horsepower versus Miles per Gallon", x="Miles per gallon (mpg)", y="Horsepower (hp)") # Add the title and axis labels.

image