Debian

How to Install R on Debian 10

R programming language is free and an open-source environment that is specifically used in graphical representation and solving statistical computing problems. R foundation supported this language for statisticians and data mining experts for data analysis and developing statistical applications. R language is most similar to the S language. R language file you can save with extensions (.r, .rdata, .rds, .rda).

This article will give you a complete description of the R programming language installation on the Debian 10 system.

Prerequisites

You should have the following prerequisites for R language installation:

  • Your system should have at least 1G or less than 1GB of RAM.  If you don’t have installed the required RAM, then use a swap file option.
  • Ensure that you must log in as a root user or should have ‘sudo’ privileges.

Open the terminal command line window. To do this, click the top section ‘Activities’ and type the ‘Terminal’ keyword in the search bar. Click on the ‘Terminal’ icon as follows:

R installation on Debian 10

The installation of R is completed into the following different steps, which we are mentioned below in detail:

The R package, which installation from the Debian repository, is usually outdated. Therefore, we will install the latest stable version of R from another repository maintained by CRAN.

Step 1: Install the required packages for adding a repository

Use the following command to install all necessary packages which are required to add a new CRAN repository:

$ sudo apt install dirmngr apt-transport-https ca-certificates software-properties-common gnupg2

Step 2: Enable repository for installation

Execute the below-mentioned command to enable the CRAN repository and import the following CRAN GPG key to your system:

$ sudo apt-key adv --keyserver keys.gnupg.net --recv-key 'E19F5F87128899B192B1A2C2AD5F960A256A04AF'

$ sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/debian buster-cran35/'

Step 3: Update system packages

Update the packages by running the below-mentioned command:

$ sudo apt update

Step 4: R installation

Use the below command on the terminal to install R on your system as follows:

$ sudo apt install r-base

Now, check the R language installation on your Debian 10 system by using the below-given command:

$ R --version

You will notice that the latest stable version of R is printed on the terminal:

Install required R packages from CRAN

You can find a wide range of R packages through the CRAN, which stands for Comprehensive R Archive Network that is the main reason R language is becoming popular day by day.

Install the following package that contains the required tools for compiling or building R packages:

$ sudo apt install build-essential

To install any R package, first, you need to open the R console environment on the terminal by typing the following command with sudo or root privileges:

$ sudo -i R

Now, you can install R packages on your system. Let’s take an example. You want to install the R package ‘Stringr’ for string manipulation. For that purpose, enter the following command in the R console as follows:

> install.packages("stringr")

Installation of the ‘Stringr’ package will complete in a few seconds. After that, you will load the relevant library by using the following command:

> library(string)

Print first Program in R Console

In this program, we will create a character vector with name tutorial as follows:

> tutorial <- c("Install", "R", "on", "Debian", "10")

Now, use the following command to print this on the terminal:

> print(tutorial)

To find the length of the string, type the command as follows:

> str_length(tutorial)

The following vector length will display on the screen:

You can also install more R packages from CRAN by using the following command:

> install.package(package_name)

Conclusion

You have learned how to install R and run R programs on the Debian 10 environment. We have provided in this article how to install R packages by using a simple command from CRAN. You can easily Install any R packages and load its associative library on your system. Now, you can easily install and use R on your Debian system.

About the author

Karim Buzdar

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.