Why R
R is a free software environment for statistical computing and graphics. It compiles and runs on a wide variety of UNIX platforms, Windows and MacOS.
The R Foundation
R is a versatile programming language that is particularly widespread between statistician community. For this reason, there are many web pages devoted to explaining how to install and use it. Moreover, there are thousands of blogs, forums and discussion platforms where users can find answers to the most common questions.
R is open-source software that is freely available for the most common platforms, like Windows, Mac e several Linux distributions.
For example, we can find countless tutorials on how to install R on our platform and a simple Google query returns millions of pages.
In our case, we will follow divide the installation of R in two steps:
- install R;
- install an interface.
We are going to install the latest version, released the 2019-07-05.
Install R
Let’s proceed with the installation.
Download R
We can retrieve the R releases in the cran site, where we can select the closest server to proceed with the download. For example, we can select the Università di Padova server and download the package for our platform.
R is open-source, thus not only we can download the installers but we can also download the source code, modify it and compile it. However, for the end of this course, we will just choose the right installer for our OS (operative system) and proceed with the installation. In the figures, you can see the case of a Mac.
From this page, we can also download older versions of R. We will see this into details later, but just remember that this is particularly important if we are working with R extensions, called packages. Sometimes some packages are not available for the latest release, so we may need to install a previous one.
In this tutorial, we install the version 3.6.1. of R.
Please note that if you are installing R on Mac, you may need to install XQuartz.
Some older computer may support the latest version of R. In that case, you can install the version 3.3.3.
Install R
Once the correct package for your platform is downloaded, the actual installation is a standard procedure on Windows and Mac. Double click on the installer and follow the instructions.
Install R on Ubuntu is particularly convenient using the command line. It is sufficient to type the following commands in the terminal.
sudo apt-get update
sudo apt-get install r-base
Use R
Once we installed R, we can already test its functionality. Going into the Applications or Program folder, we can already see it. By clicking the icon, we can run the R console, which is a basic interface. Even if it is basic, it already allows us to use all the R functions.
For example, we can already use the console as a calculator, however, this is just a small part of the R potential.
2+2
or
3*5
Even though we could run all our examples and script using the console, we will use different software, which is a complete graphic interface for R, called RStudio.
Install RStudio
Just like R, RStudio is freely available for users, even though, commercial versions for companies require a fee. At the link we can download the installer for Windows, Mac and some Linux distributions.
Once we download the installers, the automatic installation procedure should easily install the software in all the platforms.
Use RStudio
After the installation of RStudio, we can run it and we can see the initial page:
In the RStudio graphic interface, we can see three main windows. On the right, we can access the R console, which is the same we opened after the installation of R, on the left we have the windows with Environment and History and the one with Files, Plots, Packages, Help e Viewer.
After the installation, we can check if all the pre-installed packages are updated. To do this, we go to Tools
If there are updates available, let’s install them. Otherwise, RStudio should warn us that there is nothing to update.
Script
A script is a text file that contains (multiple) lines of code. It is the easiest way to save and execute more commands in RStudio.
We can open a new script in RStudio by selecting File|New File|R Script. In this way, RStudio opens a new window where we can edit and run our commands.
Now, let’s spend some time familiarizing with the studio interface and the commands in R!
Useful links
- Here we can find some notes on R, including many commands we will use during the course.
- Here we can find some notes on R (in Italian).
- At the link we can find some notes that contains many R commands divided by topic (in Italian).
© 2017-2019 Federico Reali