Friday , August 18 2017 12:33 PM
Home / Tutorials / Linux / How To Install R on Ubuntu 16.04

How To Install R on Ubuntu 16.04

How To Install R on Ubuntu 16.04 2

Introduction

R is a popular open source programming language that specializes in statistical computing and graphics. It is widely used for developing statistical software and performing data analysis. R is easily extensible, and the community is known for continuously adding user-generated packages for specific areas of study, which makes it applicable to many fields.

In this tutorial, we will install R and show how to add packages from the official Comprehensive R Archive Network (CRAN).

Prerequisites

To follow along, you will need an Ubuntu 16.04 server with:

  • a minimum of 1GB of RAM
  • a non-root user with sudo privileges.

Once these prerequisites are in place, you’re ready to begin.

Step 1 — Installing R

R is a fast-moving project, and the latest stable version isn’t always available from Ubuntu’s repositories, so we’ll start by adding the external repository maintained by CRAN:

Note: CRAN maintains the repositories within their network, but not all external repositories are reliable. Be sure to install only from trusted sources.

Once we have the trusted key in each server’s database, we can add the repository.

We’ll need to run update after this in order to include package manifests from the new repository:

If the lines above appear in the output from the update command, we’ve successfully added the repository. We can be sure we won’t accidentally install an older version.

Now we’re ready to install R:

At the time of this writing, the latest stable version from CRAN is at 3.3.1, which is displayed when you start R. Since we’re planning to install the example package for everyone on the system, we’ll start R as the root user so that the libraries will available to all users automatically:

This confirms that we’ve successfully installed R and entered its interactive shell.

Step 2 — Installing R Packages from CRAN

Part of R’s strength is the abundance of add-on packages. For demonstration purposes, we’ll installtxtplot, a library that outputs ASCII graphs, including scatterplot, line plot, density plot, acf and bar charts:

As part of the installation process, you’ll be given a choice of mirrors to install from:

We’ve entered 1 for 0-Cloud, which will connect us to the Content Delivery Network (CDN) provided by RStudio, in order to get the geographically closest option. This mirror will be set as the default for the remainder of the session. Once you exit R and re-enter, you’ll be prompted to choose a mirror again.

Note: Before the list of mirrors, the following output showed where the package was being installed.

This site-wide path is available because we ran R as root and is the correct location to make the package available to all users.

When the installation is complete, we can load txtplot:

If there are no error messages, the library has successfully loaded. Let’s see it in action now with an example which demonstrates a basic plotting function with axis labels. The example data, supplied by R’sdatasets package, contains the speed of cars and the distance required to stop based on data from the 1920s:

If you are interested to learn more about txtplot, use help(txtplot).

Any precompiled package can be installed from CRAN with install.packages(). To learn more about what’s available, you can find a listing of official packages organized by name or publication date under the Packages link on any mirror .

Now that you’ve successfully installed R.

About GOPU

Technology Enthusiast with a keen eye on the Cyber-security and other tech related developments.

Check Also

Don’t Fall For This Dangerously Convincing Ongoing Phishing Attack

Security researchers have discovered a new phishing campaign targeting Gmail users, which is so convincing …

Powered by themekiller.com anime4online.com animextoon.com apk4phone.com tengag.com moviekillers.com