Unit 1 - Setting Up The Environment-Getting R Ready
Unit 1 - Setting Up The Environment-Getting R Ready
Ready
1. Unit Overview
This unit will cover the basic aspects to allow you to get the R environment ready for use. This
unit will cover:
1. Introduction to the R
2. Installation of R Studio
3. Console and Script Editor
4. Installation of R Packages
5. R Calculator
6. R help
2. Learning Outcomes.
At the end of this unit, students should be able to:
• Understand the R environment
• Install and use R Studio
3. Introduction to the R
“R was created by Ross Ihaka and Robert Gentleman at the University of Auckland, New
Zealand, and is currently developed by the R Development Core Team” (tutorialspoint, 2018)
R is open-source programming language which can be used as a powerful statistical tool. A major
part of statistics is to Data analysis which converts “data into knowledge, insight and
understanding”. Being open-source, new packages for R are made available to cater for new
developments. R consists of statistical algorithms which are inbuilt such as machine learning and
mathematical models. R includes powerful capabilities such as easy and quick generation charts
and plots and well as the capability to integrate with Big data and perform Big Data Analytics
(Patil, 2016)
3 provision of a suite of operators for calculations (arrays, lists, vectors and matrices)
(tutorialspoint, 2018)
3.2 R and R Studio
R is a programming language can be downloaded using the comprehensive R archive network
(CRAN) (Grolemund and Wickham, 2017).
RStudio is an Integrated Development Environment (IDE) for R programming and provides a
friendly user interface (Grolemund and Wickham, 2017).
For this unit, RStudio will be used as the development environment.
4. Installation of R Studio
This section provides the basic steps to get the environment ready and follows the guildelines of
Grolemund and Wickham (2017). Follow the following steps to get your environment ready.
1. Download an open source version of RStudio from http://www.rstudio.com/download.
Note: For this module, RStudio Version 1.1.383 has been used. You might have slight
variations if you use another version.
2. Install the software from the download. Select any privacy agreements and recommended
settings.
5. Console
The R Console is where computations are performed. An expression can be input and evaluated in
the console and the results will be output in the console depending on the expression evaluated or
a graph might be displayed in the output window. To retrieve the last expression evaluated the
arrow keys can be used in the console. To stop evaluated the current expression, the Esc key can
be used.
If you followed the steps in section 4 correctly, RStudio should now be ready and should be
looking something similar to Fig.1.1. You should now be ready to use the console.
Note:
1. If you have closed RStudio after installation, don’t panick. You just have to re-open it .
2. Important aspects on screen layouts will be circled in Red as shown in Fig. 1.1
Output g
Note: that the Output area will still be blank for the moment.
6. Script Editor
Using the console, you will not be able to reuse existing codes. You can therefore use the Script
Editor instead of the Console to be able to reuse your files. You can create create a file using the
Script Editor and run it several times. Follow the following steps to create a file.
1. Click File>New>RScript a shown in Fig.1.2 to create a file using the script Editor.
Fig.1.2 Create New R Script
2. You can type R codes in the R Script Editor and save it for future use. Just type the
following line of text and Save it.
install.packages("tidyverse")
Note:
1. You can use file>Save As OR the Save icon to save your file in your preferred
location.
2. In this Unit, we will be using the Console and not the Script Editor. In subsequent units,
you might be using the Script Editor to save and run your files.
7. Installation of R Packages
R provides a wide number of packages which can be called as and when needed in the R
environment (Patil, 2016). “An R package is a collection of functions, data, and documentation
that extends the capabilities of base R” Grolemund and Wickham (2017). The majority of the
packages that you will use for Unit 1 – 3 are part of tidyverse.
Follow the following instruction to install the tidyverse package.
1. Type the single line of code just after the blinking cursor after the arrow in the Console area
as shown below and press enter
> install.packages("tidyverse")
Note:
1. R will download the packages from CRAN and install them on to your computer.
2. Make sure you have internet connectivity to install the package
2. To be able to use functions and objects from tidyverse, you now have to load it with the
librady() function as shown below. Type the command in the console and press Enter.
>library(tidyverse)
Many other excellent packages are available which are not part of tidyverse to address problems
in a different domains. As we move along, you will be instructed to install other packages if
needed.
8. R Calculator
A mathematical expression can be input in the console window and the script is evaluated and output in
the console. More details regarding mathematical operators and functions is covered in unit 2
9. R help
If you are having problems with R Studio, you can use the R help feature.
1. From the main, click on Help>R Help
2. You will see the Help screen appearing in the output window
3. You can type topics next to the search icon and press enter to see documentations
available
4. Alternatively, google is always a rich source of information and help
12. References
Grolemund, G. and Wickham, H., 2017. R for data sience. O’Reilly, January 2017 First Edition
Patil, S., 2016. Big Data Analytics Using R. International Research Journal of Engineering and
Technology (IRJET), 4.
tutorialspoint, 2016. R-Overview. Online. Available from:
https://www.tutorialspoint.com/r/r_overview.htm. [Accessed 06.02.2018]