Difference between revisions of "R/C2/Working-directories-in-RStudio/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(24 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<div style="margin-left:0cm;margin-right:0cm;">'''Title of script''': Working directories in RStudio </div>
 
  
<div style="margin-left:0cm;margin-right:0cm;">'''Authors''': Shaik Sameer (IIIT Vadodara) and Sudhakar Kumar (IIT Bombay) </div>
+
'''Title of script''': Working directories in RStudio
  
<div style="margin-left:0cm;margin-right:0cm;">'''Keywords''': R, RStudio, working directory, read csv </div>
+
'''Authors''': Shaik Sameer (IIIT Vadodara) and Sudhakar Kumar (IIT Bombay)
  
 +
'''Keywords''': R, RStudio, working directory, read csv, video tutorial
  
{| style="border-spacing:0;width:18.785cm;"
+
{| border =1
 +
|'''Visual Cue'''
 +
|'''Narration'''
 
|-
 
|-
| align=center style="background-color:#ffffff;border-top:1pt solid #000000;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | '''Visual Cue'''
+
|| Show slide  
| align=center style="background-color:#ffffff;border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | '''Narration'''
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
  
 
Opening slide
 
Opening slide
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">Welcome to this tutorial on </span><span style="background-color:#ffffff;">'''Working directories in RStudio.'''</span>
+
| Welcome to this tutorial on '''Working directories in RStudio.'''
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
| Show slide
  
 
Objectives
 
Objectives
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In this tutorial,''' '''you will learn about:
+
| In this tutorial,''' '''you will learn about:
* <div style="margin-left:1.947cm;margin-right:0cm;">'''Working directories '''in '''RStudio'''</div>
+
* '''Working directories '''in '''RStudio'''
* <div style="margin-left:1.947cm;margin-right:0cm;">How to read and store '''csv '''files in '''R'''</div>
+
* How to read and store '''csv '''files in '''R'''
  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
| Show slide
  
 
Pre-requisites
 
Pre-requisites
  
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | To understand this tutorial, you should know:  
+
| To understand this tutorial, you should know:  
* <div style="margin-left:1.947cm;margin-right:0cm;">'''R''' and '''RStudio'''</div>
+
* '''R''' and '''RStudio'''
* <div style="margin-left:1.947cm;margin-right:0cm;">Basic commands of '''R''' </div>
+
* Basic commands of '''R'''
  
 
If not, please locate the relevant tutorials on '''R''' on this website.
 
If not, please locate the relevant tutorials on '''R''' on this website.
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
| Show slide
  
 
Systems requirements
 
Systems requirements
  
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | This tutorial is recorded on
+
| This tutorial is recorded on
* <div style="margin-left:1.947cm;margin-right:0cm;">'''Ubuntu Linux OS 16.04''' </div>
+
* '''Ubuntu Linux OS 16.04'''
* <div style="margin-left:1.947cm;margin-right:0cm;">'''R '''version''' 3.2.3 '''</div>
+
* '''R '''version''' 3.2.3 '''
* <div style="margin-left:1.947cm;margin-right:0cm;">'''RStudio''' version''' 1.1.463'''</div>
+
* '''RStudio''' version''' 1.1.456'''
  
 
Install '''R''' version '''3.2.0''' or higher.
 
Install '''R''' version '''3.2.0''' or higher.
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Text on screen
+
| Text on screen
  
 
Download '''CaptaincyData.csv''' file from the '''Code files '''link
 
Download '''CaptaincyData.csv''' file from the '''Code files '''link
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We will use the '''captaincy data set '''which we created earlier in this series.
+
| We will use the '''captaincy data set '''which we created earlier in this series.
  
 
Download this data set '''CaptaincyData.csv''' from the '''Code files''' link of this tutorial.  
 
Download this data set '''CaptaincyData.csv''' from the '''Code files''' link of this tutorial.  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [Computer screen]
+
| [Computer screen]
  
 
Highlight '''CaptaincyData.csv''' in the folder '''myProject'''
 
Highlight '''CaptaincyData.csv''' in the folder '''myProject'''
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | I have downloaded and moved this '''data set''' to the folder '''myProject''' on my '''Desktop'''.  
+
| I have downloaded and moved this '''data set''' to the folder '''myProject''' on my '''Desktop'''.  
  
 
I shall set this folder as my '''Working Directory.'''
 
I shall set this folder as my '''Working Directory.'''
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
| Show slide
  
 
R scripts
 
R scripts
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
|  
* <div style="margin-left:1.947cm;margin-right:0cm;">Remember we had created two scripts, '''myfirstscript.R''' and '''mysecondscript.R'''</div>
+
* Remember we had created two scripts, '''myfirstscript.R''' and '''mysecondscript.R'''
* <div style="margin-left:1.947cm;margin-right:0cm;">Both were saved in the folder '''myProject''', on the '''Desktop.'''</div>
+
* Both were saved in the folder '''myProject''', on the '''Desktop.'''
  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide  
+
| Show slide  
  
 
Working directory  
 
Working directory  
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
|  
* <div style="margin-left:1.947cm;margin-right:0cm;">'''R''' always points to a default '''directory''' on our computer</div>
+
* '''R''' always points to a default '''directory''' on our computer
* <div style="margin-left:1.947cm;margin-right:0cm;">This '''directory''' is where '''R''' will look, by default, for files you ask it to load.</div>
+
* This '''directory''' is where '''R''' will look, by default, for files you ask it to load.
  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
|  
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We will find out what our current '''Working Directory''' is.  
+
| We will find out what our current '''Working Directory''' is.  
  
Let’s switch to '''RStudio'''.  
+
Let us switch to '''RStudio'''.  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
| [RStudio]
  
 
'''Console '''>> type '''getwd()'''
 
'''Console '''>> type '''getwd()'''
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In '''Console''', type '''getwd parentheses''' and press '''Enter'''.  
+
| In the '''Console''' window, type '''getwd parentheses''' and press '''Enter'''.  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Point to <span style="background-color:#ffffff;">'''/home/fossee'''</span><span style="background-color:#ffffff;"> in </span><span style="background-color:#ffffff;">'''Console'''</span>
+
| Point to '''/home/fossee''' in '''Console'''
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | The current '''Working Directory''' is shown in the '''console'''.  
+
| The current '''Working Directory''' is shown in the '''Console'''.  
  
 
Note down the '''directory path'''.  
 
Note down the '''directory path'''.  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
|  
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now, we will learn how to set our '''Working Directory'''.  
+
| Now, we will learn how to set our '''Working Directory'''.  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
| [RStudio]
  
 
'''Highlight '''myProject '''folder on '''Desktop
 
'''Highlight '''myProject '''folder on '''Desktop
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | I will set the folder '''myProject''' on my '''Desktop''' as my '''Working Directory'''.  
+
| I will set the folder '''myProject''' on my '''Desktop''' as my '''Working Directory'''.  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Go to '''graphical output '''window at the bottom right >> select the '''Files''' tab
+
|
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | At the top of the '''Files and Plots''' window of '''RStudio''', click on the '''Files '''tab.
+
| I am maximizing the '''Files and Plots''' window of RStudio.
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Click on the button with '''three dots''' at the right corner
+
| Go to '''graphical output '''window at the bottom right >> select the '''Files''' tab
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Go to the upper right corner of the same window.
+
| At the top of the '''Files and Plots''' window, click on the '''Files '''tab.
 +
|-
 +
| Click on the button with '''three dots''' at the right corner
 +
| Go to the upper right corner of the same window.
  
 
Below the refresh icon, click on the button with three dots.  
 
Below the refresh icon, click on the button with three dots.  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Point to '''Go To Folder'''
+
| Point to '''Go To Folder'''
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | '''Go To Folder''' window appears.
+
| '''Go To Folder''' window appears.
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Select '''myProject''' folder >>''' '''click''' Open'''
+
| Select '''myProject''' folder >>''' '''click''' Open'''
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Select the folder which you want to make as your '''Working Directory '''and''' '''click''' Open'''.
+
| Select the folder which you want to make as your '''Working Directory '''and''' '''click''' Open'''.
  
 
I am selecting '''myProject''' located on my '''Desktop'''.  
 
I am selecting '''myProject''' located on my '''Desktop'''.  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Point to the two scripts under '''Files '''tab
+
| Point to the two scripts under '''Files '''tab
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Under '''Files''' tab, you can see that the two '''scripts '''created earlier, have been loaded.
+
| Under '''Files''' tab, you can see that the two '''scripts '''created earlier, have been loaded.
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
| [RStudio]
  
 
Select '''More >> Set As Working Directory'''
 
Select '''More >> Set As Working Directory'''
  
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now, below the '''Files''' tab, click on the '''More''' button with the blue gear symbol.  
+
| Now, below the '''Files''' tab, click on the '''More''' button with the blue gear symbol.  
  
 
From the dropdown menu, select the '''Set As Working Directory''' option.  
 
From the dropdown menu, select the '''Set As Working Directory''' option.  
Line 127: Line 129:
 
Now this folder is set as your '''Working Directory.'''  
 
Now this folder is set as your '''Working Directory.'''  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Point to the '''Console'''
+
| Point to the '''Console'''
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | You may verify this by looking at the '''Console'''.  
+
| You may verify this by looking at the '''Console'''.  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
|
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | There is one other way to set the''' Working Directory '''also.
+
| Now, I am minimizing the '''Files and Plots''' window.
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
|  
 +
| There is one other way to set the''' Working Directory '''also.
 +
|-
 +
| [RStudio]
  
 
'''Console >> '''type '''setwd("/home/fossee/'''
 
'''Console >> '''type '''setwd("/home/fossee/'''
  
 
'''Desktop/myProject") '''
 
'''Desktop/myProject") '''
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In the '''Console''', type '''setwd. '''
+
| In the '''Console''', type '''setwd. '''
  
 
Now, inside parentheses, type the desired '''folder path '''within double quotes.
 
Now, inside parentheses, type the desired '''folder path '''within double quotes.
Line 144: Line 149:
 
Press '''Enter'''.
 
Press '''Enter'''.
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight '''CaptaincyData.csv''' in the '''File '''tab
+
| Highlight '''CaptaincyData.csv''' in the '''File '''tab
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now, we will learn how to read and store a '''csv '''file called '''CaptaincyData.csv.'''
+
| Now, we will learn how to read and store a '''csv '''file called '''CaptaincyData.csv.'''
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |
+
|  
 
+
  
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We shall declare a variable '''captaincy''' to store '''CaptaincyData.csv'''.
+
| We shall declare a '''variable captaincy''' to store '''CaptaincyData.csv'''.
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
| [RStudio]
  
 
'''captaincy = read.csv("CaptaincyData.csv")'''
 
'''captaincy = read.csv("CaptaincyData.csv")'''
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In '''Console '''window, type '''captaincy''' space '''equal''' sign space '''read.csv'''
+
| In the '''Console '''window, type '''captaincy''' space '''equal''' sign space '''read.csv'''
  
 
Now, '''CaptaincyData.csv''' inside double quotes in '''parentheses '''and press '''Enter'''.  
 
Now, '''CaptaincyData.csv''' inside double quotes in '''parentheses '''and press '''Enter'''.  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight '''read.csv '''
+
| Highlight '''read.csv '''
  
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | '''read.csv()''' '''function '''is used to read a file and to create a '''data-frame''' from it.  
+
| '''read.csv function '''is used to read a file and to create a '''data-frame''' from it.  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
| [RStudio]
  
 
'''View(captaincy)'''
 
'''View(captaincy)'''
  
 
Highlight the data frame in '''Source '''window  
 
Highlight the data frame in '''Source '''window  
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now, we use '''View() function''' to see the stored '''data frame'''.  
+
| Now, we use '''View function''' to see the stored '''data frame'''.  
  
In '''Console '''window, type '''View captaincy '''in '''parentheses '''and press''' Enter. '''
+
In the '''Console '''window, type '''View captaincy '''in '''parentheses '''and press''' Enter. '''
  
The contents of '''captaincy''' '''data frame''' appears in the '''Source''' window.  
+
The contents of '''captaincy data frame''' appears in the '''Source''' window.  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
|
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | This brings us to the end of this tutorial. Let us summarize.
+
|I am maximizing the '''Source''' window to see the '''captaincy''' data set.  
 +
|-  
 +
|  
 +
| This brings us to the end of this tutorial. Let us summarize.
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
| Show slide
  
 
Summary
 
Summary
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | At the end of this tutorial, we have learnt how to
+
| In this tutorial, we have learned
* <div style="margin-left:1.947cm;margin-right:0cm;">get and set a '''working directory'''</div>
+
* How to get and set a '''working directory'''
* <div style="margin-left:1.947cm;margin-right:0cm;">read and store a '''csv''' file </div>
+
* How to read and store a '''csv''' file  
  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
| Show slide
  
 
Assignment
 
Assignment
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We now suggest an assignment.
+
| We now suggest an assignment.
* <div style="margin-left:1.947cm;margin-right:0cm;">Create a new folder and make it your '''Working Directory'''.</div>
+
* Create a new folder on your computer and make it your '''Working Directory'''.
  
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
| Show slide
  
 
About the Spoken Tutorial Project
 
About the Spoken Tutorial Project
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | The video at the following link summarises the Spoken Tutorial project.
+
| The video at the following link summarises the Spoken Tutorial project.
  
 
Please download and watch it.
 
Please download and watch it.
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
| Show slide
  
 
Spoken Tutorial Workshops
 
Spoken Tutorial Workshops
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We conduct workshops using Spoken Tutorials and give certificates.
+
| We conduct workshops using Spoken Tutorials and give certificates.
  
 
Please contact us.
 
Please contact us.
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show Slide
+
| Show Slide
  
 
Forum to answer questions
 
Forum to answer questions
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Pls post your timed queries in this forum.
+
| Pls post your timed queries in this forum.
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show Slide
+
| Show Slide
  
 
Forum to answer questions
 
Forum to answer questions
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Pls post your general queries in this forum.
+
| Pls post your general queries in this forum.
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show Slide
+
| Show Slide
  
 
Textbook Companion
 
Textbook Companion
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">The </span><span style="background-color:#ffffff;">'''FOSSEE '''</span><span style="background-color:#ffffff;">team coordinates coding of solved examples of popular books.</span>
+
| The '''FOSSEE '''team coordinates coding of solved examples of popular books.
  
We give honorarium and certificates for those who do this.
+
We give honorarium and certificates to those who do this.
  
 
For more details, please visit these sites.
 
For more details, please visit these sites.
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show Slide
+
| Show Slide
  
 
Acknowledgement
 
Acknowledgement
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | The Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India
+
| The Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India
 
|-
 
|-
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show Slide
+
| Show Slide
  
 
Thank You
 
Thank You
| style="background-color:#ffffff;border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | This script for this tutorial was contributed by Shaik Sameer (FOSSEE Fellow 2018).
+
| This script for this tutorial was contributed by Shaik Sameer (FOSSEE Fellow 2018).
  
 
This is Sudhakar Kumar from IIT Bombay signing off. Thanks for watching.
 
This is Sudhakar Kumar from IIT Bombay signing off. Thanks for watching.
 
|-
 
|-
 
|}
 
|}
<div style="margin-left:0cm;margin-right:0cm;"></div>
 

Latest revision as of 15:42, 24 April 2019

Title of script: Working directories in RStudio

Authors: Shaik Sameer (IIIT Vadodara) and Sudhakar Kumar (IIT Bombay)

Keywords: R, RStudio, working directory, read csv, video tutorial

Visual Cue Narration
Show slide

Opening slide

Welcome to this tutorial on Working directories in RStudio.
Show slide

Objectives

In this tutorial, you will learn about:
  • Working directories in RStudio
  • How to read and store csv files in R
Show slide

Pre-requisites

To understand this tutorial, you should know:
  • R and RStudio
  • Basic commands of R

If not, please locate the relevant tutorials on R on this website.

Show slide

Systems requirements

This tutorial is recorded on
  • Ubuntu Linux OS 16.04
  • R version 3.2.3
  • RStudio version 1.1.456

Install R version 3.2.0 or higher.

Text on screen

Download CaptaincyData.csv file from the Code files link

We will use the captaincy data set which we created earlier in this series.

Download this data set CaptaincyData.csv from the Code files link of this tutorial.

[Computer screen]

Highlight CaptaincyData.csv in the folder myProject

I have downloaded and moved this data set to the folder myProject on my Desktop.

I shall set this folder as my Working Directory.

Show slide

R scripts

  • Remember we had created two scripts, myfirstscript.R and mysecondscript.R
  • Both were saved in the folder myProject, on the Desktop.
Show slide

Working directory

  • R always points to a default directory on our computer
  • This directory is where R will look, by default, for files you ask it to load.
We will find out what our current Working Directory is.

Let us switch to RStudio.

[RStudio]

Console >> type getwd()

In the Console window, type getwd parentheses and press Enter.
Point to /home/fossee in Console The current Working Directory is shown in the Console.

Note down the directory path.

Now, we will learn how to set our Working Directory.
[RStudio]

Highlight myProject folder on Desktop

I will set the folder myProject on my Desktop as my Working Directory.
I am maximizing the Files and Plots window of RStudio.
Go to graphical output window at the bottom right >> select the Files tab At the top of the Files and Plots window, click on the Files tab.
Click on the button with three dots at the right corner Go to the upper right corner of the same window.

Below the refresh icon, click on the button with three dots.

Point to Go To Folder Go To Folder window appears.
Select myProject folder >> click Open Select the folder which you want to make as your Working Directory and click Open.

I am selecting myProject located on my Desktop.

Point to the two scripts under Files tab Under Files tab, you can see that the two scripts created earlier, have been loaded.
[RStudio]

Select More >> Set As Working Directory

Now, below the Files tab, click on the More button with the blue gear symbol.

From the dropdown menu, select the Set As Working Directory option.

Now this folder is set as your Working Directory.

Point to the Console You may verify this by looking at the Console.
Now, I am minimizing the Files and Plots window.
There is one other way to set the Working Directory also.
[RStudio]

Console >> type setwd("/home/fossee/

Desktop/myProject")

In the Console, type setwd.

Now, inside parentheses, type the desired folder path within double quotes.

Press Enter.

Highlight CaptaincyData.csv in the File tab Now, we will learn how to read and store a csv file called CaptaincyData.csv.
We shall declare a variable captaincy to store CaptaincyData.csv.
[RStudio]

captaincy = read.csv("CaptaincyData.csv")

In the Console window, type captaincy space equal sign space read.csv

Now, CaptaincyData.csv inside double quotes in parentheses and press Enter.

Highlight read.csv read.csv function is used to read a file and to create a data-frame from it.
[RStudio]

View(captaincy)

Highlight the data frame in Source window

Now, we use View function to see the stored data frame.

In the Console window, type View captaincy in parentheses and press Enter.

The contents of captaincy data frame appears in the Source window.

I am maximizing the Source window to see the captaincy data set.
This brings us to the end of this tutorial. Let us summarize.
Show slide

Summary

In this tutorial, we have learned
  • How to get and set a working directory
  • How to read and store a csv file
Show slide

Assignment

We now suggest an assignment.
  • Create a new folder on your computer and make it your Working Directory.
Show slide

About the Spoken Tutorial Project

The video at the following link summarises the Spoken Tutorial project.

Please download and watch it.

Show slide

Spoken Tutorial Workshops

We conduct workshops using Spoken Tutorials and give certificates.

Please contact us.

Show Slide

Forum to answer questions

Pls post your timed queries in this forum.
Show Slide

Forum to answer questions

Pls post your general queries in this forum.
Show Slide

Textbook Companion

The FOSSEE team coordinates coding of solved examples of popular books.

We give honorarium and certificates to those who do this.

For more details, please visit these sites.

Show Slide

Acknowledgement

The Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India
Show Slide

Thank You

This script for this tutorial was contributed by Shaik Sameer (FOSSEE Fellow 2018).

This is Sudhakar Kumar from IIT Bombay signing off. Thanks for watching.

Contributors and Content Editors

Nancyvarkey, Sudhakarst