11
Chapter 3
INTERFACE DESCRIPTION
This chapter provides more details about the interface of RStudio and an explanation
of the most important commands.
3.1 Starting the RStudio software
In order to implement or open the program, there are many methods that can be
used by the keyboard or the mouse. We mention the two most important and most used
methods with the mouse which are to click directly on the icon in the taskbar or double-
click on the icon on the desktop (see the figure 2.6). As for using the keyboard, you can
press the Windows key, type the name of the program, and then press Enter.
3.2 Interface description
The interface of RStudio can be divided into five parts as shown in the figure 3.1.
These parts are:
Figure 3.1: The parts of RStudio interface
12
1. The first part builds the address bar, which shows the name of the open program
or file.
2. The second part shows the menu bar, which contains eleven menus. Each menu
contains a set of important commands for creating programs in the R language.
3. The third part shows a group of tools that are quickly used to carry out important
and frequently used commands. The fourth part shows the workspace through which
programs are written and results are shown after implementation. This section
contains three tabs.
4. The fifth part contains four tabs, and it shows information about the environment,
connections, and help with using the R program.
5. The six-part, which shows six tabs, and shows the files stored in the computer, the
results, the sources, the helper, . . . etc.
3.3 Creating R script on RStudio
The creation of a new R script within RStudio can be done by going up to the "File"
menu and click on "New file-> R script" from RStudio interface (see the figure 3.2). A
dialog box will appear requesting the file name and save location. This action allows the
creation of a file with the extension (.R).
13
Figure 3.2: Create a New R Script using RStudio.
After writing the commands to be executed in the R software, the file must be saved
in one of the ways, either by using the Save command from the File menu, or by using
the shortcut "Ctrl+S".
The commands written in a R file can be executed by using one of the ways, either by
using the "Run Selected Line(s)" command from the Code menu, or by using the shortcut
"Ctrl+Enter" (see the figure 3.3) or the tool "Run" from toolbar of the script file (see the
figure ??).
14
Figure 3.3: Run the R Script file using RStudio.
- To open an existing file you use either the File menu and clicking the Open File...
command or the Recent Files command to select from recently opened files.
3.3.1 Basic Operations in RStudio
In order to use the R program, there are many basic operations that can be performed
on a file, and these operations can be summarized in the following table 3.1.
15
Command Menu Shortcut Description
Clear Console Edit Ctrl+L To clear the screen and delete all execution result.
Close File Ctrl+W Close currently file opened.
Quit Session... File Ctrl+Q Close session opened.
Find... Edit Ctrl+F Search a word or a variable or a function in the open file.
Word Count Edit Display a number of words in the open file.
Go To Line... Edit Alt+Maj+S Go to the line designated by a number.
Extract Function Code / Convert the selected code into a re-usable function.
Extract Variable Code / Convert the selected code into a variable.
Show Toolbar View / Show toolbar if it is hidden.
Hide Toolbar View / Hide the toolbar.
Actual Size View Ctrl+0 Show the window in its normal size,
Zoom In View Ctrl+= Increase the size of the window.
Show plots View Ctrl+6 Show the figures.
Show packages View Ctrl+7 Show the existing packages.
Save as Image... Plot / Save the plot as an image.
Remove plot Plot / Delete the selected plot.
Terminate R Session / Terminate the execution of the R software.
Restart R Session / Restart the execution of the R software.
Load workspace Session / Load the folder workspace into the RStudio software.
Clear workspace Session / Clear the folder workspace.
Execute Next Line Debug F10 Execute the next line in the current code.
Continue Debug Maj+F5 Continue the execution of stopped code.
Table 3.1: The most important operations in RStudio.
3.4 Packages in R
R packages (or libraries) are collections of functions and commands that can be sued
in R for treating and analysing data.
3.4.1 Using packages
There are three types of R packages.
[Link] Base Packages
The base packages are installed and distributed with a base installation of R. They
provide the essential syntax and commands for programming, computing, graphics pro-
duction, basic arithmetic, and statistical functionality. Some of them are loaded in mem-
ory when R starts; this can be displayed with the function search as shown in figure
3.4:
16
Figure 3.4: Base Packages with the function search.
The list of the functions in a package can be displayed with the use of the function
library (see the example displayed in figure 3.5:
Figure 3.5: Functions of the graphics package.
17
[Link] Recommended Packages
Recommended packages are included with a typical R installation but aren’t auto-
matically loaded. They extend the functionality of the base packages to include slightly
more specialized statistical methods and computational tools. There are 15 recommended
packages as illustrated in figure 3.6.
Figure 3.6: Recommended Packages in R
[Link] Contributed Packages
Finally, a huge collection of user-contributed packages can be added to the list of
statistical methods available in R.
3.4.2 Installing and updating Packages
The method to install a package depends on the operating system and whether R was
installed from the sources or pre-compiled binaries. The installation and loading of R
packages can be done within R by going up to the Packages menu and clicking on Install
package(s) from CRAN.
There are several useful functions to manage packages such as installed packages,
update packages, or download packages. these actions can be performed by using the
Tools menu from RStudio interface as shown in the figure 3.7 or by using Packages menu
from R software interface as shown in the figure 3.8. Packages can also be installed using
the command "[Link]".
18
Figure 3.7: Installing and Updating Packages in RStudio
Figure 3.8: Installing and Updating Packages in R
[Link] Example of installing package
To install the tidyr package, we use the function "[Link]("tidyr")" as written
in the figure 3.9. This package provides three main functions for tidying your messy data:
gather() , separate() and spread().
19
Figure 3.9: Installing "tidyr" package in RStudio.
3.4.3 Constructing Packages
R allows you to create and publish your own packages for users to use. More details
on developing your own packages are given in the book [1].