Welcome to this tutorial on Introduction to R Studio.
In this tutorial, you will learn about these features of Rstudio:
Source and Console windows
Workspace; Plots and Files window
How to install packages of R
To understand this tutorial, you should know:
Elementary Maths
Basic commands of R
If not, please locate the relevant tutorials on R on this website.
This tutorial is recorded on
Ubuntu Linux Operating System 16.04
R version 3.2.3
RStudio version 1.1.456
Install R version 3.2.0 or higher.
Let us switch to Rstudio.
The window in the top left corner is the Source window.
It is used to edit a script and run it.
The window in the bottom left corner is the Console window.
It is used to install packages or to run a particular command.
The upper right window is the Workspace window.
It stores all the variables used during execution of commands under the Environment tab.
Place your cursor on the inside edges of all the windows.
A four-headed arrow symbol appears.
You can drag this to resize your windows for better visibility.
Let us declare some variables.
In the Console, type testSample (capital S) space less than symbol followed by hyphen space c.
Now, in parentheses, type 1 comma 2 comma 3 comma 4.
Press Enter to execute this line.
You can see the variable testSample in the Environment window.
The lower right window is the Plots and Files window.
The Files tab is used to keep track of Working Directories.
We will learn more about Working Directory later in this series.
The Plots tab shows all the graphical output.
Let us plot the variable testSample.
In the Console, type plot testSample capital S in parentheses. Press Enter.
You can now see the plot in the Plots window.
Let us look at the Environment window in the upper right corner.
We will clear this variable in this window.
At the top of the Environment window, click on the broom icon.
A Confirm Remove Objects window appears.
Ensure that the box Include hidden objects is checked and click on Yes.
Now, there is no variable in the Environment.
Click in the Plots window and click on the broom icon.
A Clear Plots text box appears.
The text reads, “Are you sure you want to clear all of the plots in the history?”
Click Yes.
Now, let us try plotting this variable again.
In the Console, again type plot testSample in parentheses as before.
Press Enter.
No plot is generated.
Instead, we see:
Error in plot(testSample) : object 'testSample' not found
It means that the variable testSample has been removed from our Workspace.
So, you should be careful with this broom icon in the Environment window.
Next to Environment, the History tab stores all our actions.
Here, we can see the lines that have been executed so far.
Let us declare two variables, firstVar and secondVar, which will be used later.
In the Console, type first capital V a r space less than symbol followed by hyphen space 6.
Press Enter.
Next, type second capital V a r space less than symbol followed by hyphen space 8. Press Enter.
Our Console window is filled with the previous commands.
We need to clean the Console before moving on.
Click in the Console window and press Ctrl+L together.
Clicking on the broom icon in the upper right corner of the Console will also clear it.
To see this icon, place the cursor under the maximizer button of the Console window.
You will see a hand symbol and the text, Clear Console Ctrl+L.
Packages in R
R packages are a collection of R functions, compiled code and sample data.
Stored under a directory called library in the R environment.
By default, R installs a set of packages
Let us switch back to RStudio.
Now click on the Environment tab again.
To see the list of R packages installed in your system, in the Console, type library parentheses.
Press Enter.
A tab named R packages available opens up in Source window.
Let us install a new package named MASS.
Please make sure that you are connected to the Internet.
In the Console window, type install dot packages.
Now, MASS inside double quotes in parentheses.
Press Enter.
We will need to wait until R installs the package.
There is another way to install a package. Let us install another package named ggplot2.
In the top menu bar of RStudio, click on the Tools button.
From the drop-down menu, select the Install Packages option.
In the Packages field, type the name of the package ggplot2
Ensure that Install dependencies box is checked and click on the Install button.
To load a package, we use library function and provide the package name as an argument.
We will load the MASS package now.
In the Console window, type library MASS in parentheses and press Enter.
Now we will use fractions function available in the MASS package.
In the Console window, type f r a c t.
RStudio shows the fractions option.
Press Enter to select it.
You can use this feature while typing commands.
Only remember that R is case-sensitive.
After fractions, type, in parentheses, firstVar division slash secondVar.
Press Enter.
You can see the reduced fraction ¾ in the Console.
In the Console, we can also type firstVar division slash secondVar.
It gives the result in decimal form.
This brings us to the end of this tutorial. Let us summarize.
We have learnt about, Source and Console windows. Source and Console windows
Workspace; Plots and Files window
How to install packages of R
The video at the following link summarises the Spoken Tutorial project.
Please download and watch it.
We conduct workshops using Spoken Tutorials and give certificates.
Please contact us.
Do you have questions in THIS Spoken Tutorial?
Choose the minute and second where you have the question.
Explain your question briefly.
Someone from the FOSSEE team will answer them.
Please visit this site.
Do you have any general / technical questions?
Please visit the forum given in the link.
The FOSSEE team coordinates coding of solved examples of popular books.
We give honorarium and certificates for those who do this.
For more details, please visit these sites.
The Spoken Tutorial project is funded by MHRD, Govt. of India
This script has been contributed by Shaik (FOSSEE Fellow 2018) and Sudhakar from FOSSEE project.
This is Vidhya Iyer from IIT Bombay signing off. Thanks for watching.