This article was first published in: https://www.itcoder.tech/posts/how-to-install-r-on-ubuntu-20-04/
R is an open source programming language and free environment, mainly used for statistical analysis and drawing. It is supported by the R Foundation and is mainly used for statistical analysis. It is mainly used by data statistics and analysts to develop statistical software and for data analysis.
This article mainly describes how to install R on Ubuntu 20.04.
Before proceeding with this guide, please make sure you meet the following prerequisites:
The R packages included in the default Ubuntu software sources are often out of date. We will install R from the CRAN software source.
To install R on Ubuntu 20.04, follow the steps below:
sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'
sudo apt install r-base
R --version
Output:
R version 4.0.1(2020-06-06)--"See Things Now"Copyright(C)2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu(64-bit)...
that's it. R has been installed on your Ubuntu machine, and you can start using it.
One of the main reasons for R's popularity is that many software packages are provided through the Comprehensive R Archive Network (CRAN).
To compile the R package, you need to install the build-essential
package:
sudo apt install build-essential
To demonstrate, we will install a package called stringr
, which provides a quick implementation of common string operations.
When you run as root, the package will be installed globally and available to all system users. If you start R without using sudo, this will only work for the current user.
Open the R terminal:
R
Output:
>
To install the stringr
package, enter:
install.packages("stringr")
The installation will take some time. Once completed, enter the following command to load the library:
library(stringr)
Next, create a simple string with the command'tutorial':
tutorial <-c("How","to","Install","R","on","Ubuntu","20.04")
Running the following function will print out the length of each string:
str_length(tutorial)
[1]3271265
You can find more R packages in CRAN Package Page, and install them via install.packages()
.
We have shown you how to install R on Ubuntu 20.04 and how to compile and install R packages.
If you have any questions, please contact us in the following ways:
WeChat:
WeChat group: add the above WeChat, remark the WeChat group
QQ: 3217680847
QQ Group: 82695646
Recommended Posts