R, together with Python, is a commonly used programming language for statistical computing and data analytics. An increasingly popular and extensible language with an active community, R offers many user-generated packages for specific areas of study, which makes it applicable to many fields.
The Aridhia DRE Workspace comes with R integrated into the workspace but if you want to use it in the Virtual Desktop, you will need to follow the instructions below to install it yourself.
Installing R on Ubuntu 18.04
Note that these instructions are for installing R on your Linux VM for the first time. If you want to install other R versions, please see this RStudio article about installing multiple versions of R on Linux.
1. Obtain the relevant GPG Key
Because the VM has restricted access to the Internet, you will need to do this step outside the Workspace, e.g. on your personal machine.
If you are running Linux, then you need to run these commands in your terminal:
gpg --keyserver keyserver.ubuntu.com --recv-key E298A3A825C0D65DFD57CBB651716619E084DAB9 gpg -a --export E298A3A825C0D65DFD57CBB651716619E084DAB9 > E298A3A825C0D65DFD57CBB651716619E084DAB9.pub
This will obtain the CRAN GPG key and export it to a *.pub file.
If you are using Windows, then you need to obtain CRAN repository key from the Ubuntu Keyserver website. Open the link in your browser, right-click with your mouse and select 'Save as'. Name the key E298A3A825C0D65DFD57CBB651716619E084DAB9.pub.
2. Upload the GPG key to the Workspace
Upload the key to the workspace by going into the Add tab and pressing 'Upload File'. This will open a new dialog, where you can find the exported GPG key (**.pub* file) in your local file system and upload it to the workspace. More information about uploading files can be found on the Uploading files via the Workspace page.
3. Add the CRAN GPG key to your system
Once the key is uploaded, go back to your Virtual Desktop and open the terminal. First,
cd into the directory where your GPG key is:
Then add the CRAN GPG key to your system:
sudo apt-key add E298A3A825C0D65DFD57CBB651716619E084DAB9.pub
4. Enable the CRAN repository
For the latest R 4.x version use this command:
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/'
For the latest R 3.x version:
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'
5. Add user group for permissions
sudo touch /etc/staff-group-for-usr-local
Before adding a new group, check if the
staff group already exists in your VM:
This command will return a list of users. If
staff is on the list skip to the next step, otherwise, you can add it by running:
sudo adduser workspace staff
For these changes to take effect, restart the VM.
6. Update the packages list and install R
sudo apt update sudo apt install r-base -y
7. Create and set tmp directory
sudo mkdir /opt/tmpR sudo chown -R workspace:workspace /opt/tmpR echo "TMPDIR=\"/opt/tmpR\"" | sudo tee -a /etc/R/Renviron.site
8. Test that the right version of R has been installed
In the terminal, just run
R. This should open the R console, and the first line of the text should display the version of R you are currently running.
Now you are ready to use R in your Linux VM. For a better development experience, we also recommend installing RStudio. You can find the instructions here.
9. Installing non-R dependencies
In order to install some R Packages, you need non-R dependencies to be installed in the VM. Some of the most common dependencies can be installed using:
sudo apt-get install -y libpq-dev libxml2-dev libcurl4-openssl-dev libssl-dev libv8-dev
Installing R on Windows
1. Download R installer
Open the browser and navigate to cloud.r-project.org. Click ‘Download R for Windows’, which will open a new page with subdirectories. You will want to download binaries for base distribution, so click on ‘base’ subdirectory.
By clicking on the link at the top of the page, you will download the latest R distribution. If you want an older version, scroll down to the bottom of the page and navigate to ‘Previous Releases’.
2. Install R
Navigate to the Downloads folder, and double click on the executable. Follow the instructions to complete the installation.
Now you are ready to use R in your Windows VM. For a better development experience, we also recommend installing RStudio. You can find the instructions here.