Difference between revisions of "R/C2/Introduction-to-R-script/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 7: Line 7:
  
 
{| style="border-spacing:0;width:18.785cm;"
 
{| style="border-spacing:0;width:18.785cm;"
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| align=center style="background-color:#ffffff;border-top:1.75pt solid #000000;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | '''Visual Cue'''
+
| align=center| '''Visual Cue'''
| align=center style="background-color:#ffffff;border:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | '''Narration'''
+
| align=center| '''Narration'''
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
|| Show slide
  
 
Opening slide
 
Opening slide
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt 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;">'''Introduction to R script.'''</span>
+
|| <span style="background-color:#ffffff;">Welcome to this tutorial on </span><span style="background-color:#ffffff;">'''Introduction to R script.'''</span>
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In this tutorial,''' '''you will learn:* <div style="margin-left:1.947cm;margin-right:0cm;">How to work with an '''R&nbsp;script&nbsp;'''in''' RStudio'''</div>
+
|| In this tutorial,''' '''you will learn:* <div style="margin-left:1.947cm;margin-right:0cm;">How to work with an '''R script '''in '''RStudio''' </div>
  
  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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
Line 29: Line 29:
  
  
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | To understand this tutorial, you should know: * <div style="margin-left:1.947cm;margin-right:0cm;">'''R''' and '''RStudio'''</div>
+
|| To understand this tutorial, you should know: * <div style="margin-left:1.947cm;margin-right:0cm;">'''R''' and '''RStudio'''</div>
 
* <div style="margin-left:1.947cm;margin-right:0cm;">Basic commands of '''R''' </div>
 
* <div style="margin-left:1.947cm;margin-right:0cm;">Basic commands of '''R''' </div>
  
Line 35: Line 35:
  
 
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:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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
Line 42: Line 42:
  
  
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | This tutorial is recorded on* <div style="margin-left:1.947cm;margin-right:0cm;">'''Ubuntu Linux OS 16.04''' </div>
+
|| This tutorial is recorded on* <div style="margin-left:1.947cm;margin-right:0cm;">'''Ubuntu Linux OS 16.04''' </div>
 
* <div style="margin-left:1.947cm;margin-right:0cm;">'''R '''version''' 3.2.3 '''</div>
 
* <div style="margin-left:1.947cm;margin-right:0cm;">'''R '''version''' 3.2.3 '''</div>
 
* <div style="margin-left:1.947cm;margin-right:0cm;">'''RStudio''' version''' 1.1.463'''</div>
 
* <div style="margin-left:1.947cm;margin-right:0cm;">'''RStudio''' version''' 1.1.463'''</div>
Line 49: Line 49:
  
 
Install '''R''' version '''3.2.0''' or higher.
 
Install '''R''' version '''3.2.0''' or higher.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide
+
|| Show slide
  
 
What is '''R script'''
 
What is '''R script'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt 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;">An '''R script''' is a plain '''text file''' in which you save your '''R code'''</div>
+
|| * <div style="margin-left:1.947cm;margin-right:0cm;">An '''R script''' is a plain '''text file''' in which you save your '''R code'''</div>
 
* <div style="margin-left:1.947cm;margin-right:0cm;">'''Script '''allows you to show your work to others, and also reproduce and modify the results </div>
 
* <div style="margin-left:1.947cm;margin-right:0cm;">'''Script '''allows you to show your work to others, and also reproduce and modify the results </div>
  
  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show slide  
+
|| Show slide  
  
 
Creating a folder for our project  
 
Creating a folder for our project  
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt 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;">Before you begin please create a folder named '''myProject'''</div>
+
|| * <div style="margin-left:1.947cm;margin-right:0cm;">Before you begin please create a folder named '''myProject'''</div>
 
* <div style="margin-left:1.947cm;margin-right:0cm;">I have already created this folder on my '''Desktop'''. </div>
 
* <div style="margin-left:1.947cm;margin-right:0cm;">I have already created this folder on my '''Desktop'''. </div>
  
Line 70: Line 70:
  
 
Later, I shall set this folder as my '''Working Directory'''.  
 
Later, I shall set this folder as my '''Working Directory'''.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
|| [RStudio]
  
 
RStudio window  
 
RStudio window  
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Let us switch to&nbsp;'''RStudio'''.
+
|| Let us switch to '''RStudio'''.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
|| [RStudio]
  
 
Click on the green '''plus sign >> '''select '''R Script''' from the dropdown  
 
Click on the green '''plus sign >> '''select '''R Script''' from the dropdown  
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We will now create a new '''R script'''.* <div style="margin-left:1.27cm;margin-right:0cm;">In the top left corner of '''RStudio, '''click on the green '''plus sign. '''</div>
+
|| We will now create a new '''R script'''.* <div style="margin-left:1.27cm;margin-right:0cm;">In the top left corner of '''RStudio, '''click on the green '''plus sign. '''</div>
 
* <div style="margin-left:1.27cm;margin-right:0cm;">Now from the dropdown menu, select '''R Script'''.</div>
 
* <div style="margin-left:1.27cm;margin-right:0cm;">Now from the dropdown menu, select '''R Script'''.</div>
  
  
 
|-
 
|-
| style="border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the new '''R''' '''script Untitled1'''
+
| style="border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the new '''R''' '''script Untitled1'''
| style="border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | A new '''R script''' appears in the '''Source''' window.
+
| style="border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | A new '''R script''' appears in the '''Source''' window.
  
  
 
You can also create a new '''R script''' by pressing '''Ctrl+Shift+N''' together.
 
You can also create a new '''R script''' by pressing '''Ctrl+Shift+N''' together.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Click on '''File'''
+
|| Click on '''File'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now let’s save this '''R''' '''script''' first.
+
|| Let us save this '''R''' '''script''' first.
  
 
In the top left corner of the screen, click on the '''File''' option.
 
In the top left corner of the screen, click on the '''File''' option.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Click on '''Save '''option
+
|| Click on '''Save '''option
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Then click on '''Save''' to save the script.
+
|| Then click on '''Save''' to save the script.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Select the directory '''myProject'''>> type name<span style="color:#ff00ff;"> </span>'''myfirstscript'''>> click on '''Save '''button
+
|| Select the directory '''myProject'''>> type name<span style="color:#ff00ff;"> </span>'''myfirstscript'''>> click on '''Save '''button
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Select the directory where you want to save your '''R script'''.  
+
|| Select the directory where you want to save your '''R script'''.  
  
 
I am saving it in the folder '''myProject''' on my '''Desktop''',''' '''with the name '''myfirstscript.'''
 
I am saving it in the folder '''myProject''' on my '''Desktop''',''' '''with the name '''myfirstscript.'''
  
Finally, click on '''Save''' button.
+
Finally, click on the '''Save''' button.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Point to '''myfirstscript.R '''in the '''Source '''window
+
|| Point to '''myfirstscript.R '''in the '''Source '''window
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now you can see that the file is named as '''myfirstscript.R'''.  
+
|| Now you can see that the file is named as '''myfirstscript.R'''.  
  
 
'''RStudio''' automatically adds '''dot R''' at the end of the filename.  
 
'''RStudio''' automatically adds '''dot R''' at the end of the filename.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now, let us write some lines of code in the '''script''' file '''myfirstscript.R'''.  
+
|| Now, let us write some lines of code in the '''script''' file '''myfirstscript.R'''.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
|| [RStudio]
  
 
'''testSample <- c(1,2,3,4)'''
 
'''testSample <- c(1,2,3,4)'''
Line 119: Line 119:
  
  
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We will create a '''vector''' named '''testSample''' with one two three four as its '''elements'''.
+
|| We will create a '''vector''' named '''testSample''' with one two three four as its '''elements'''.
  
  
Line 125: Line 125:
  
  
In the '''Source '''window, type '''testSample''' space '''less than''' symbol.Now type '''hyphen space c 1 comma 2 comma 3 comma 4 in parentheses.'''
+
In the '''Source '''window, type '''testSample''' space '''less than''' symbol.Now type '''hyphen space c 1 comma 2 comma 3 comma 4 '''in''' parentheses.'''
  
  
 
Press '''Enter. '''
 
Press '''Enter. '''
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight '''<- symbol'''
+
|| Highlight '''<- symbol'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | You may also use '''equal''' sign in place of '''less than''' symbol followed by '''hyphen'''.
+
|| You may also use '''equal''' sign in place of '''less than''' symbol followed by '''hyphen'''.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight '''Save''' icon
+
|| Highlight '''Save''' icon
  
  
  
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In the '''Source '''window, to the left of the checkbox '''Source on Save, '''
+
|| In the '''Source '''window, to the left of the checkbox '''Source on Save, '''
 
+
click on the '''Save''' icon.
+
  
 +
click on the '''Save''' icon.
  
 
Or, press '''Ctrl+S '''together to save the file.
 
Or, press '''Ctrl+S '''together to save the file.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
|| [RStudio]
  
 
'''print(testSample)'''
 
'''print(testSample)'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We will now use the '''print function''' to display the values in '''testSample''' '''vector.'''
+
|| We will now use the '''print function''' to display the values in '''testSample''' '''vector.'''
  
  
 
In the '''Source '''window, type p r i  
 
In the '''Source '''window, type p r i  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the predicted functions
+
|| Highlight the predicted functions
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | '''RStudio''' automatically starts suggesting different '''functions'''.  
+
|| '''RStudio''' automatically starts suggesting different '''functions'''.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | You can navigate this list of '''functions''' by using the '''up (↑)''' and '''down (↓)''' arrow keys on the keyboard.  
+
|| You can navigate this list of '''functions''' by using the '''up (↑)''' and '''down (↓)''' arrow keys on the keyboard.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Press '''Enter'''
+
|| Press '''Enter'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | To select a particular '''function''', just press '''Enter'''.  
+
|| To select a particular '''function''', just press '''Enter'''.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Finish typing''' print testSample '''in '''parentheses '''and press '''Enter'''.  
+
|| Finish typing''' print testSample '''in '''parentheses '''and press '''Enter'''.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Press '''Ctrl+S '''
+
|| Press '''Ctrl+S '''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now let’s save the file and '''run''' it with these two lines only.  
+
|| Now let’s save the file and '''run''' it with these two lines only.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
|| [RStudio]
  
Highlight '''Source '''button in the '''Source '''window  
+
Highlight '''Source''' button in the '''Source''' window
 
+
Highlight the '''output '''in '''Console '''window
+
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In the top right corner of the '''Source '''window, click on the '''Source '''button.
+
  
 +
Highlight the output in '''Console''' window
 +
|| In the top right corner of the '''Source '''window, click on the '''Source '''button.
  
 
You can see the line-by-line execution of the '''script''' in the '''Console'''.  
 
You can see the line-by-line execution of the '''script''' in the '''Console'''.  
Line 182: Line 180:
  
 
For this, you need to first click in the '''script '''window.  
 
For this, you need to first click in the '''script '''window.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
|| [RStudio]
  
'''firstVar''' '''<nowiki>= 10 </nowiki>'''
+
'''firstVar''' '''<nowiki>= 10</nowiki>'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now let’s declare a '''variable firstVar''' with value of ten in the '''Source '''window.
+
|| Now let’s declare a '''variable firstVar''' with value of ten''' '''in the '''Source''' window.
  
  
 
Type''' firstVar''' with capital V space '''equal''' sign space 10 and press '''Enter. '''
 
Type''' firstVar''' with capital V space '''equal''' sign space 10 and press '''Enter. '''
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Please note that '''R''' language is case-sensitive.  
+
|| Please note that '''R''' language is case-sensitive.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
|| [RStudio]
  
'''print(firstVar)'''
+
'''print(firstVar) '''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We will now use the '''print function '''to show the value of '''firstVar'''.
+
|| We will now use the '''print function '''to show the value of '''firstVar'''.
  
  
In the '''Source '''window, type print and in parentheses, start typing '''firstVar'''.
+
In the '''Source '''window, type '''print '''and in '''parentheses''', start typing '''firstVar. '''
  
  
Line 206: Line 204:
  
  
Press '''Enter '''to go to the next line.  
+
Press '''Enter''' to go to the next line.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
|| [RStudio]
  
 
'''secondVar = 15'''
 
'''secondVar = 15'''
  
 
'''print(secondVar)'''
 
'''print(secondVar)'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Next let’s declare another '''variable secondVar''' with value of fifteen.  
+
|| Next let’s declare another '''variable secondVar''' with value of fifteen.
  
  
In the '''Source '''window, type''' secondVar''' space '''equal''' sign space 15 and press '''Enter'''.
+
In the '''Source''' window, type''' secondVar''' space '''equal''' sign space 15 and press '''Enter'''.
  
  
Now, as shown before, type '''print secondVar '''in '''parentheses '''to show its value and press '''Enter'''.
+
Now, as shown before, type '''print''' '''secondVar''' in '''parentheses''' to show its value and press '''Enter'''<span style="background-color:#ffffff;color:#252525;">.</span>
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We can add '''comments''' to our code by using '''<nowiki># hash </nowiki>'''symbol followed by our '''comment'''.  
+
|| We can add '''comments''' to our code by using '''<nowiki># hash </nowiki>'''symbol followed by our '''comment'''.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
|| [RStudio]
  
 
'''<nowiki># Creating an R script </nowiki>'''
 
'''<nowiki># Creating an R script </nowiki>'''
  
 
Highlight the comment line and first line of code  
 
Highlight the comment line and first line of code  
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Type''' hash''' symbol space '''Creating an R script''' before the declaration of '''testSample vector.'''
+
|| Type''' hash''' symbol space '''Creating an R script''' before the declaration of '''testSample vector.'''
  
 
'''R '''interprets each line of code.  
 
'''R '''interprets each line of code.  
  
 
Please make sure that your '''comment''' and the first line of code appear in separate lines.
 
Please make sure that your '''comment''' and the first line of code appear in separate lines.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Click on the line '''print(secondVar)'''
+
|| Click on the line '''print(secondVar)'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now, let’s '''comment''' the line '''print(secondVar)'''.
+
|| Now, let’s '''comment''' the line '''print(secondVar)'''.
  
 
To do that, first click on this line.  
 
To do that, first click on this line.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | from '''Code '''option >>  
+
|| from '''Code '''option >>  
  
 
'''Comment/Uncomment Lines'''  
 
'''Comment/Uncomment Lines'''  
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Then from the top menu bar of '''RStudio, '''click on the '''Code''' option.  
+
|| Then from the top menu bar of '''RStudio''',''' '''click on the '''Code''' option.  
  
 
From the dropdown menu, click on the '''Comment/Uncomment Lines '''option.  
 
From the dropdown menu, click on the '''Comment/Uncomment Lines '''option.  
  
 
This option helps us to '''comment''' as well as '''uncomment''' a line.
 
This option helps us to '''comment''' as well as '''uncomment''' a line.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight '''hash '''symbol
+
|| Highlight '''hash '''symbol
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | On doing so, we see a '''hash '''symbol with space.
+
|| On doing so, we see a '''hash '''symbol with space.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | '''Delete # symbol'''
+
|| Delete''' # symbol'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | For now, we will '''uncomment print(secondVar)''' and save our''' script'''.
+
|| For now, we will '''uncomment print(secondVar)''' and save our '''script'''.
  
Delete '''<nowiki>#</nowiki>''' '''hash '''symbol at the beginning of this line.  
+
Delete '''<nowiki># hash</nowiki>''' symbol at the beginning of this line.
  
 
+
Or, you can press '''Ctrl+Z''' to uncomment this line.
Or, you can press '''Ctrl+Z''' to uncomment this line.  
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
|-
+
|| [RStudio]
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
  
 
Click on the '''Source''' button
 
Click on the '''Source''' button
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now let’s run the '''script''' file.  
+
|| Now let’s run the '''script''' file.  
  
  
In the top right corner of the '''Source''' window, click on the '''Source button'''.
+
In the top right corner of the '''Source''' window, click on the '''Source '''button.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the '''Console '''window
+
|| Highlight the '''Console '''window
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | On doing so, line by line execution of the '''script '''is shown in the '''Console '''window.
+
|| On doing so, line by line execution of the '''script '''is shown in the '''Console '''window.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the output in '''Console'''
+
|| Highlight the output in '''Console'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | The '''sample vector [1 2 3 4] '''is printed.  
+
|| The '''sample vector [1 2 3 4] '''is printed.  
  
  
 
The values of two '''variables,''' 10 and 15 are printed.  
 
The values of two '''variables,''' 10 and 15 are printed.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We will clear the '''Console '''by clicking on the broom icon.  
+
|| We will clear the '''Console''' by clicking on the broom icon.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the file '''myfirstscript.R'''
+
||
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now let’s move ahead.
+
|| Now let’s move ahead.  
 +
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
 +
|| Highlight the file '''myfirstscript.R'''
 +
|| Suppose, we want to run only a '''block of code '''after '''print(testSample) '''from the file '''myfirstscript.R. '''
 +
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
 +
|| [RStudio]
  
 
+
Highlighting the block of code
Suppose, we want to run a '''block of code''' after '''print(testSample) '''from the file '''myfirstscript.R. '''
+
|| First, select or highlight the''' block of code''', starting from '''firstVar''' '''equals 10 '''to the end.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
|| Click on''' Run''' button
 
+
|| Then in the top right corner of the '''Source '''window, click on the '''Run '''button with an arrow.  
Highlight the block of code
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | First, select or highlight the''' block of code''', starting from '''firstVar''' '''equals 10 '''to the end.  
+
|| Highlight the output in '''Console '''window
|-
+
|| Now you can see the output of only the highlighted part of the code in the '''Console''' window.  
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Click on''' Run''' button
+
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Then in the top right corner of the '''Source '''window, click on the '''Run '''button with an arrow.  
+
|-
+
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the output in '''Console '''window
+
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now you can see the output of only the highlighted part of the code in the '''Console''' window.  
+
  
  
 
The output shows the values of two '''variables, '''10 and 15 only.
 
The output shows the values of two '''variables, '''10 and 15 only.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Run a block using '''Ctrl+Enter'''
+
|| Run a block using '''Ctrl+Enter'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | You can also run a particular '''block''' by highlighting it and pressing '''Ctrl+Enter''' together.
+
|| You can also run a particular '''block''' by highlighting it and pressing '''Ctrl+Enter''' together.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Click on broom icon
+
|| Click on broom icon
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We will clear the '''Console '''window by clicking on the broom icon.  
+
|| We will clear the '''Console''' window by clicking on the broom icon.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
|| [RStudio]
  
 
Creating an R script using '''Ctrl+Shift+N'''
 
Creating an R script using '''Ctrl+Shift+N'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now let’s create another '''R script'''.
+
|| Now let’s create another '''R script'''.
  
 
Use '''Ctrl+Shift+N''' to open a new '''script'''.  
 
Use '''Ctrl+Shift+N''' to open a new '''script'''.  
  
 
Save this '''script''' in the same folder '''myProject''' with the name '''mysecondscript.'''  
 
Save this '''script''' in the same folder '''myProject''' with the name '''mysecondscript.'''  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now let’s learn how to load''' myfirstscript.R''' into '''mysecondscript.R'''.  
+
|| Now let’s learn how to load''' myfirstscript.R''' into '''mysecondscript.R'''.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | [RStudio]
+
|| [RStudio]
  
 
'''Source'''
 
'''Source'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Go to''' myfirstscript.R '''and run it by clicking on the '''Source''' button.
+
|| Go to''' myfirstscript.R '''and run it by clicking on the '''Source''' button.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the '''source '''line
+
|| Highlight the '''source '''line
  
 
'''source('~/Desktop/myProject/myfirstscript.R', echo=TRUE)'''.
 
'''source('~/Desktop/myProject/myfirstscript.R', echo=TRUE)'''.
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | In the '''Console''' window, scroll up to locate the '''source '''for this script.<span style="background-color:#ffffff;color:#0000ff;">''' '''</span>
+
|| In the '''Console''' window, scroll up to locate the '''source''' for this '''script'''.<span style="background-color:#ffffff;color:#0000ff;">''' '''</span>
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Copying the '''source '''line
+
|| Copying the '''source '''line
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Copy it without the '''less than symbol. '''
+
|| Copy it without the '''less than symbol. '''
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Back to '''mysecondscript.R'''
+
|| Back to '''mysecondscript.R'''
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now let’s get back to our new script '''mysecondscript.R'''
+
|| Now let’s get back to our new '''script''' '''mysecondscript.R'''
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Pasting the '''source '''line
+
|| Pasting the '''source '''line
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Paste what we have just copied, at the top of the''' script mysecondscript.R '''
+
|| Paste what we have just copied, at the top of the''' script mysecondscript.R '''
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We can press '''Enter '''after comma for better visibility.
+
|| We can press '''Enter''' after comma for better visibility.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Type '''print("Script loaded")'''  
+
|| Type '''print("Script loaded")'''  
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Next, write one more line to ensure that the execution is from this '''script''' only.  
+
|| Next, write one more line to ensure that the execution is from this '''script''' only.  
  
  
In the '''Source '''window, type '''print and then the following words in parentheses.'''
+
In the '''Source''' window, type '''print '''and then the following words in''' parentheses.'''
  
In double quotes, '''Script space loaded.'''
+
In double quotes''', Script space loaded.'''
  
  
 
Press''' Enter. '''
 
Press''' Enter. '''
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Press '''Ctrl+S''' keys
+
|| Press '''Ctrl+S''' keys
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Save the '''script.'''
+
|| Save the '''script.'''
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Click on the broom icon in '''Console '''
+
|| Click on the broom icon in '''Console'''  
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Let us clear the '''Console '''again by clicking on the broom icon.  
+
|| Let us clear the Console again by clicking on the broom icon.  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Press '''Ctrl+Shift+Enter''' keys
+
|| Press '''Ctrl+Shift+Enter''' keys
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Now run the script by pressing <span style="background-color:#ffffff;">'''Ctrl+Shift+Enter'''</span><span style="background-color:#ffffff;"> together. </span>
+
|| Now run the '''script''' by pressing <span style="background-color:#ffffff;">'''Ctrl+Shift+Enter'''</span><span style="background-color:#ffffff;"> together. </span>
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Highlight the output
+
|| Highlight the output
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">You can see the output in the </span><span style="background-color:#ffffff;">'''Console'''</span><span style="background-color:#ffffff;"> window and verify the results.</span>
+
|| <span style="background-color:#ffffff;">You can see the output in the </span><span style="background-color:#ffffff;">'''Console'''</span><span style="background-color:#ffffff;"> window and verify the results.</span>
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt 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.
+
|| This brings us to the end of this tutorial. Let us summarize.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt 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* <div style="margin-left:1.947cm;margin-right:0cm;">Create, save and '''run''' an '''R script'''</div>
+
|| At the end of this tutorial, we have learned how to* <div style="margin-left:1.947cm;margin-right:0cm;">Create, save and run an '''R script'''</div>
  
  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | We now suggest an assignment.* <div style="margin-left:1.947cm;margin-right:0cm;">Create a script and save it on Desktop as testscript.R</div>
+
|| We now suggest an assignment.* <div style="margin-left:1.947cm;margin-right:0cm;">Create a '''script''' and save it on '''Desktop''' as '''testscript.R '''</div>
* <div style="margin-left:1.947cm;margin-right:0cm;">Load myfirstscript.R in this script and run it.</div>
+
* <div style="margin-left:1.947cm;margin-right:0cm;">Load '''myfirstscript.R''' in this script and run it.</div>
  
  
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt 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:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt 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:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Pls post your timed queries in this forum.
+
|| <span style="background-color:#ffffff;">Do you have questions in THIS </span><span style="background-color:#ffffff;">'''Spoken Tutorial?'''</span>
|-
+
 
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show Slide
+
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.
 +
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
 +
||
 +
 
 +
Show Slide
  
 
Forum to answer questions
 
Forum to answer questions
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Pls post your general queries in this forum.
+
|| Do you have any general / technical questions?
|-
+
 
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" | Show Slide
+
Please visit the forum given in the link.
 +
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
 +
|| Show Slide
  
 
Textbook Companion
 
Textbook Companion
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt 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>
+
|| <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>
  
 
We give honorarium and certificates for those who do this.
 
We give honorarium and certificates for those who do this.
  
 
For more details, please visit these sites.
 
For more details, please visit these sites.
|-
+
|- style="background-color:#ffffff;border:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt 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:0.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;"
| style="background-color:#ffffff;border-top:none;border-bottom:1.75pt solid #000000;border-left:1.75pt 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:1.75pt solid #000000;border-left:1.75pt solid #000000;border-right:1.75pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.203cm;padding-right:0.191cm;" |  
+
||  
  
The 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).
  
  
Line 430: Line 440:
 
|-
 
|-
 
|}
 
|}
 +
<div style="margin-left:0cm;margin-right:0cm;"></div>

Revision as of 23:37, 10 December 2018

Title of script: Introduction to R script
Authors: Shaik Sameer (IIIT Vadodara) and Sudhakar Kumar (IIT Bombay)
Keywords: R, RStudio, script


Visual Cue Narration
Show slide

Opening slide

Welcome to this tutorial on Introduction to R script.
Show slide

Objectives

In this tutorial, you will learn:*
How to work with an R script in RStudio


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.463


Install R version 3.2.0 or higher.

Show slide

What is R script

*
An R script is a plain text file in which you save your R code
  • Script allows you to show your work to others, and also reproduce and modify the results


Show slide

Creating a folder for our project

*
Before you begin please create a folder named myProject
  • I have already created this folder on my Desktop.


I shall now save all my scripts and data sets in this folder.


Later, I shall set this folder as my Working Directory.

[RStudio]

RStudio window

Let us switch to RStudio.
[RStudio]

Click on the green plus sign >> select R Script from the dropdown

We will now create a new R script.*
In the top left corner of RStudio, click on the green plus sign.
  • Now from the dropdown menu, select R Script.


Highlight the new R script Untitled1 A new R script appears in the Source window.


You can also create a new R script by pressing Ctrl+Shift+N together.

Click on File Let us save this R script first.

In the top left corner of the screen, click on the File option.

Click on Save option Then click on Save to save the script.
Select the directory myProject>> type name myfirstscript>> click on Save button Select the directory where you want to save your R script.

I am saving it in the folder myProject on my Desktop, with the name myfirstscript.

Finally, click on the Save button.

Point to myfirstscript.R in the Source window Now you can see that the file is named as myfirstscript.R.

RStudio automatically adds dot R at the end of the filename.

Now, let us write some lines of code in the script file myfirstscript.R.
[RStudio]

testSample <- c(1,2,3,4)


We will create a vector named testSample with one two three four as its elements.


We have already learned how to create vectors earlier in this series.


In the Source window, type testSample space less than symbol.Now type hyphen space c 1 comma 2 comma 3 comma 4 in parentheses.


Press Enter.

Highlight <- symbol You may also use equal sign in place of less than symbol followed by hyphen.
Highlight Save icon


In the Source window, to the left of the checkbox Source on Save,

click on the Save icon.

Or, press Ctrl+S together to save the file.

[RStudio]

print(testSample)

We will now use the print function to display the values in testSample vector.


In the Source window, type p r i

Highlight the predicted functions RStudio automatically starts suggesting different functions.
You can navigate this list of functions by using the up (↑) and down (↓) arrow keys on the keyboard.
Press Enter To select a particular function, just press Enter.
Finish typing print testSample in parentheses and press Enter.
Press Ctrl+S Now let’s save the file and run it with these two lines only.
[RStudio]

Highlight Source button in the Source window

Highlight the output in Console window

In the top right corner of the Source window, click on the Source button.

You can see the line-by-line execution of the script in the Console.


You can also run the script by pressing Ctrl+Shift+Enter together.


For this, you need to first click in the script window.

[RStudio]

firstVar = 10

Now let’s declare a variable firstVar with value of ten in the Source window.


Type firstVar with capital V space equal sign space 10 and press Enter.

Please note that R language is case-sensitive.
[RStudio]

print(firstVar)

We will now use the print function to show the value of firstVar.


In the Source window, type print and in parentheses, start typing firstVar.


RStudio shows firstVar; press Enter to select it.


Press Enter to go to the next line.

[RStudio]

secondVar = 15

print(secondVar)

Next let’s declare another variable secondVar with value of fifteen.


In the Source window, type secondVar space equal sign space 15 and press Enter.


Now, as shown before, type print secondVar in parentheses to show its value and press Enter.

We can add comments to our code by using # hash symbol followed by our comment.
[RStudio]

# Creating an R script

Highlight the comment line and first line of code

Type hash symbol space Creating an R script before the declaration of testSample vector.

R interprets each line of code.

Please make sure that your comment and the first line of code appear in separate lines.

Click on the line print(secondVar) Now, let’s comment the line print(secondVar).

To do that, first click on this line.

from Code option >>

Comment/Uncomment Lines

Then from the top menu bar of RStudio, click on the Code option.

From the dropdown menu, click on the Comment/Uncomment Lines option.

This option helps us to comment as well as uncomment a line.

Highlight hash symbol On doing so, we see a hash symbol with space.
Delete # symbol For now, we will uncomment print(secondVar) and save our script.

Delete # hash symbol at the beginning of this line.

Or, you can press Ctrl+Z to uncomment this line.

[RStudio]

Click on the Source button

Now let’s run the script file.


In the top right corner of the Source window, click on the Source button.

Highlight the Console window On doing so, line by line execution of the script is shown in the Console window.
Highlight the output in Console The sample vector [1 2 3 4] is printed.


The values of two variables, 10 and 15 are printed.

We will clear the Console by clicking on the broom icon.
Now let’s move ahead.
Highlight the file myfirstscript.R Suppose, we want to run only a block of code after print(testSample) from the file myfirstscript.R.
[RStudio]

Highlighting the block of code

First, select or highlight the block of code, starting from firstVar equals 10 to the end.
Click on Run button Then in the top right corner of the Source window, click on the Run button with an arrow.
Highlight the output in Console window Now you can see the output of only the highlighted part of the code in the Console window.


The output shows the values of two variables, 10 and 15 only.

Run a block using Ctrl+Enter You can also run a particular block by highlighting it and pressing Ctrl+Enter together.
Click on broom icon We will clear the Console window by clicking on the broom icon.
[RStudio]

Creating an R script using Ctrl+Shift+N

Now let’s create another R script.

Use Ctrl+Shift+N to open a new script.

Save this script in the same folder myProject with the name mysecondscript.

Now let’s learn how to load myfirstscript.R into mysecondscript.R.
[RStudio]

Source

Go to myfirstscript.R and run it by clicking on the Source button.
Highlight the source line

source('~/Desktop/myProject/myfirstscript.R', echo=TRUE).

In the Console window, scroll up to locate the source for this script.
Copying the source line Copy it without the less than symbol.
Back to mysecondscript.R Now let’s get back to our new script mysecondscript.R
Pasting the source line Paste what we have just copied, at the top of the script mysecondscript.R
We can press Enter after comma for better visibility.
Type print("Script loaded") Next, write one more line to ensure that the execution is from this script only.


In the Source window, type print and then the following words in parentheses.

In double quotes, Script space loaded.


Press Enter.

Press Ctrl+S keys Save the script.
Click on the broom icon in Console Let us clear the Console again by clicking on the broom icon.
Press Ctrl+Shift+Enter keys Now run the script by pressing Ctrl+Shift+Enter together.
Highlight the output You can see the output in the Console window and verify the results.
This brings us to the end of this tutorial. Let us summarize.
Show slide

Summary

At the end of this tutorial, we have learned how to*
Create, save and run an R script


Show slide

Assignment

We now suggest an assignment.*
Create a script and save it on Desktop as testscript.R
  • Load myfirstscript.R in this script and run it.


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

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.

Show Slide

Forum to answer questions

Do you have any general / technical questions?

Please visit the forum given in the link.

Show Slide

Textbook Companion

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.

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