How to set up R on Ubuntu 14.04

Introduction

R is a popular open source programming language specifically used for statistical calculations and graphics. It is widely used by statisticians to develop statistical software and perform data analysis. One of R's strengths is that it allows users to create and submit their own packages, so it is highly and easily expandable. As we all know, the R community is very active and is known for constantly adding user-generated statistical software packages for specific research areas, which makes R suitable for many research areas.

The "Comprehensive R Archive Network" (CRAN) is a series of sites (called mirrors) that carry the same materials and consist of many R packages and the R distribution itself. You can download R and many R packages from any CRAN mirror, but we will use the RStudio mirror.

In this guide, we will learn how to set up R on Tencent CVM running Ubuntu 14.04. If CVM is running another operating system, most instructions still apply, but you may need to modify some commands. It will take about 10-15 minutes after completing this guide.

prerequisites

In this tutorial, you will need:

Step 1-Set up APT

To install R, we will use the APT (Advanced Packaging Tool) tool. It uses a special file to list the sources from which the software package should be downloaded. That file is /etc/apt/sources.list. In order to get the latest version of R, we need to add the correct repository to the source list by adding a line to the sources file. The exact line you need to add will vary depending on the exact Ubuntu version. For Ubuntu 14.04, run the following command to add the correct repository to /etc/apt/sources.list.

sudo sh -c 'echo "deb http://cran.rstudio.com/bin/linux/ubuntu trusty/" >> /etc/apt/sources.list'

To verify the package downloaded using APT, we must add a public key. The Ubuntu archive on CRAN is signed with a key with ID E084DAB9. Add this key to your system.

gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9

Next we need to add the key to apt.

gpg -a --export E084DAB9 | sudo apt-key add -

Step 2-Install R.

Now that APT has been set up correctly, we can use it to install R.

First, we need to update the list of available packages because we updated the source list.

sudo apt-get update

Now we can install R. When asked if we are sure we want to download the package, we use the -y flag to automatically answer "Yes".

sudo apt-get-y install r-base

At this point, you should install the latest R version on Tencent CVM. You can test it by running the R command.

R

You should see output similar to the following.

R version 3.2.1(2015-06-18)--"World-Famous Astronaut"Copyright(C)2015 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu(64-bit)
​
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()'for distribution details.
​
 Natural language support but running in an English locale
​
R is a collaborative project with many contributors.
Type 'contributors()'for more information and
' citation()' on how to cite R or R packages in publications.
​
Type 'demo()'for some demos,'help()'for on-line help, or
' help.start()'for an HTML browser interfaceto help.
Type 'q()' to quit R.
​
>

You are now in the R interactive shell and can run any R command.

Exit R, and use the following q() function to return to Tencent CVM:

q(save ="no")

Step 3-Install R package from CRAN

Now that R is installed on your CVM, any user on CVM can use R. When R is installed, it will automatically install many default packages, but in order to do anything really meaningful in R, you may need to install additional packages. In order to install many software packages, it is important to have at least 1 GB of RAM.

As mentioned earlier, CRAN not only hosts R itself, but also many R software packages. To install a new R package hosted on CRAN, or update an existing R package, you can use the install.packages() function in R. If you want to install the package somepackage, you can open R and run the following R command.

# This is an example,do not run this
install.packages("somepackage")

However, by default, any package installed by a specific user in R can only be used by that user. For example, if the user sammy installs somepackage, then the user jessie will not be able to use somepackage before installing it.

You can install the R package by all users who have installed Tencent CVM as root. As an example, let's install the shiny package, which is a very popular package for creating web applications from R code. The installation package as a one-way root will log in as root, run R, and run the install.packages() command. However, it is recommended not to log in as root, so we can only run R commands as root. We will also specify the repos parameter to download the package from the RStudio CRAN repository, which is the same as we used when downloading R itself.

sudo su --c "R -e \"install.packages('shiny', repos = 'http://cran.rstudio.com/')\""

By installing the package in this way instead of opening R and running the install.packages() command, the shiny package is available to all users on the CVM.

Let's verify if shiny is installed correctly by trying to load. Start an R session.

R

In R, try to load the shiny package.

library(shiny)

Running the previous command should not cause an error. Now exit R.

q(save ="no")

Step 4-Install devtools package

Although many R packages are hosted on CRAN and can be installed using the built-in install.packages() function, there are more packages hosted on GitHub but not on CRAN. To install the R package from GitHub, we need to use the devtoolsR package, so let's install it.

The devtoolsR package needs to install three system packages libcurl4-gnutls-dev, libxml2-dev and libssl-devc on Tencent CVM. Install these three packages:

sudo apt-get-y install libcurl4-gnutls-dev libxml2-dev libssl-dev

The devtoolsR package can now be installed. Remember, we want to install it using the same method as above, not install it in an R session, because devtools should be available to all users.

sudo su --c "R -e \"install.packages('devtools', repos='http://cran.rstudio.com/')\""

The above installation command devtools may take several minutes to complete.

Step 5-Install R package from GitHub

Now that we have installed devtools, we can install any R package on GitHub using the install_github() function. As with the CRAN package, when installing the GitHub package, you need to run the command from the system shell to make the package available to all users. Let's try to install the shinyjs GitHub package, which can add functionality to the shiny package. The GitHub package is defined by its author (daattali) and its name (shinyjs).

sudo su --c "R -e \"devtools::install_github('daattali/shinyjs')\""

Let's verify that shinyjs is installed correctly by trying to load. Start an R session.

R

In R, try to load the shinyjs package.

library(shinyjs)

Running the previous command may produce some messages, but no error messages will be displayed. Now exit R.

q(save ="no")

Next step

You can now install R on Tencent CVM.

To learn more about R, please visit Official R website, or try Use the swirl package to learn R practice and interactively.

For more information about CRAN and the information it provides, please visit CRAN official website.

In this guide, we have completed the steps required to set up R on Ubuntu 14.04 Tencent CVM. We also learned the difference between installing R packages from GitHub and CRAN, and how to ensure that these packages are available to all users on CVM.

For more Ubuntu tutorials, please go to [Tencent Cloud + Community] (https://cloud.tencent.com/developer?from=10680) to learn more.


Reference: "How To Set Up R on Ubuntu 14.04"

Recommended Posts

How to set up R on Ubuntu 14.04
How to set up Shiny Server on Ubuntu 14.04
How to set up time synchronization on Ubuntu 18.04
How to install R on Ubuntu 20.04
How to set up a DNS server on Ubuntu 18.04
How to set PostgreSQL startup on Ubuntu 16.04
How to set up a Masterless Puppet environment on Ubuntu 14.04
How to set up a firewall with UFW on Ubuntu 14.04
How to set up vsftpd for anonymous downloads on Ubuntu 16.04
How to set up a production Elasticsearch cluster on Ubuntu 14.04
How to set up an Apache virtual host on Ubuntu 16.04
How to set up an Apache virtual host on Ubuntu 20.04
How to set up password authentication with Nginx on Ubuntu 14.04
How to set up vsftpd for user directories on Ubuntu 16.04
How to set static IP on Ubuntu 18.04 Server
How to install R on Ubuntu 18.04 [Quick Start]
How to set up SSH keys on CentOS 8
How to set up Ghost one-click app for Ubuntu 16.04
How to set a fixed IP based on Ubuntu 16.04
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install R on CentOS 8
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install PrestaShop on Ubuntu 16.04
How to upgrade to PHP 7 on Ubuntu 14.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04
How to install Anaconda on Ubuntu 20.04
How to install Prometheus on Ubuntu 16.04
How to install Jenkins on Ubuntu 18.04
How to deploy Django on Ubuntu 14.04
How to install Apache on Ubuntu 20.04
How to install Moodle on Ubuntu 16.04
How to install Solr 5.2.1 on Ubuntu 14.04
How to install Teamviewer on Ubuntu 16.04
How to secure Nginx on Ubuntu 14.04
How to install MariaDB on Ubuntu 20.04
How to install Nginx on Ubuntu 20.04
How to install Mono on Ubuntu 20.04
How to install Go on Ubuntu 20.04
How to install Zoom on Ubuntu 20.04
How to uninstall software on Ubuntu
How to install Nginx on Ubuntu 16.04
How to install OpenCV on Ubuntu 20.04
How to install Spotify on Ubuntu 20.04