Update Systen
First lets update the system to make sure packages and dependencies are up to date before installation.
sudo apt dist-upgrade
Installing R
The default package for R included in the Debian 11 repositories features an older stable version of R. In your terminal; you can use the following to install R:
For your reference the r-base package contains the main parts of the R programming language. The package is here, and the R programming language reference is here.
Voila with the apt install command R is installed now type the command R at the shell to open the interpeter:
Running this command will launch R in your terminal and give you the current version installed (4.0.4). This confirms that R has been successfully installed on your Debian 11.
Run some simple R Program interactively
You can use basic variables and do arithmetic operations in R programming language, you can even do this interactively in the R terminal. Here is a simple code example for sum of 2 numbers.
y <- 4
z <- x+y
print(z)
Basic If Else Conditional in R
We won’t teach R programming this post, but just to get you started a little, R has many common programming language features. We will demonstrate the IF ELSE conditional of R programming language in this example. Here is the code:
y <- 4
if (x+y>10) {
print("Result is big")
} else {
print("Result is not too big")
}
But running in interactive terminal R helps make a little less typing as shown below:
Run from Script
We can also run R programs from a script. Lets run code from above example in a script like this at the bash terminal using the Rscript command as shown here:
Conclusion
R is a programming language used for statistics and data science. It can be easily installed on Debian Linux as shown in this article and you can be writing code and running it in R in just minutes.