The R programming language is extremely popular for performing static calculations and graphics. It is usually used by statisticians to develop statistical software and analyze data. The main peculiarity and also the advantage of the R language is its extensibility. The user has the opportunity to create and publish his own packages. In addition, the R community is active, constantly adding custom statistical packages for specific areas of science. Which makes R applicable in many fields. These instructions will show you how to install and configure R in Ubuntu. Most of the instructions will work for other operating systems as well, just a few commands will need to be changed.
First things first, what you need to have is Ubuntu and 1 GB of RAM on your system. If there is not enough memory, you need to connect a swap partition. You can install R from the official Ubuntu repositories. To do this, run the command:
$ sudo apt install r-base
True, with this command, you can only get a version dated 2018:
To get the latest version, you need to add the R-Project
repository and install the language environment from there.
To do this, the following commands are executed:
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
$ sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'
You can use a special option to perform an automatic installation of the program:
$ sudo apt-get -y install r-base
Now you have the latest version of the R programming language installed on your system. You can safely start testing it:
$ R
Without special settings, R installs several standard packages. However, the user may have a desire to install additional packages. To do so, you need to have at least 1 GB of RAM. To install or upgrade packages in CRAN
, you must use the R function install.packages()
.
For example, if you want to install package_name
, then use this code:
> install.packages("package_name")
Note that this will initialize the package for the current user only. It will not be available to other users. You can also install the R package for all users by running R with root access.
For a good example, let's install the shiny package, considered the most popular among web application developers in R. You can simply run the R command using sudo. The repo parameter specifies from which repository the package will be downloaded.
$ sudo su - -c "R -e "install.packages('shiny', repos = 'http://cran.rstudio.com/')""
You can make sure that the package is available to everyone by entering a simple command:
$ R
Next, download the package:
$ > library(shiny)
That's it. Now you know how you can install the R package in Ubuntu and initialize it from CAN
.