Change R Version

These instructions describe how to install a different version of R (r-base) on a cluster. You can check the default r-base version that each Databricks Runtime version is installed with in the System environment section in each Databricks Runtime release note.

List available r-base-core versions

To list the versions of r-base-core that can be installed and the version format:

  1. Paste the following shell command in a notebook cell:

    add-apt-repository 'deb [arch=amd64,i386] xenial//'
    apt-get -y update
    apt-cache madison r-base-core
  2. Run the cell.

For example, you can install version 3.3.3 by specifying 3.3.3-1xenial0.

Install a specific R version

  1. Paste the following shell command into a notebook cell. Set <r-version> to the R version to be installed. Set <init-script-path> to a file path under /dbfs where this init script will be saved.

    mkdir -p $(dirname $INIT_SCRIPT_PATH)
    echo "set -e
    # Add the repository containing another version of R
    add-apt-repository 'deb [arch=amd64,i386] xenial//'
    apt-get -y update
    # Uninstall current R version
    apt-get remove -y r-base-core
    # Install another version of R
    apt-get install -y r-base-core=$R_VERSION
    # Must install Rserve to use Databricks notebook
    R -e \"install.packages('Rserve', repos='', type = 'source')\"
    R -e \"install.packages('hwriterPlus', repos='')\"" > $INIT_SCRIPT_PATH
  2. Run the notebook cell to save the init script to a file on DBFS.

  3. Create a cluster that uses the init script. When specifying the init script path in the cluster creation UI, modify the format of the init script path to change /dbfs to dbfs:/. For example, if <init-script-path> is set to /dbfs/examplepath/, then in the cluster creation UI specify the init script path dbfs:/examplepath/

  4. After the cluster starts up, verify that the desired R version is installed by running %r R.version in a notebook cell.