A ".R" file is where you write code to run procedures and/or commands to analyze or manipulate data.
Opening a blank .R file can be done on the main window of RStudio. To start, open RStudio on your computer and in the upper left corner of the window click on "File" --> "New File"--> "R Script" to begin writing code. You may also type 'control+shift+N'.
To save a .R file, click on the floppy disk icon highlighted in the red circle.
We can think of a .R file as a ‘live’ word document, where we write commands that tell RStudio what to do with our data from descriptive statistics to regression models.
RStudio code is written with commands which are the main function or analysis you want RStudio to do in a line of code.
By starting a line with a “ # “, we can write notes and comments that will appear green. RStudio does not recognize this as code.
#Frequency of language
table(SLID$language)
You can also write blocks of text that do not appear as code by also starting the text with a " # ".
Blocking off code
To run code, that is to tell RStudio what you want to do, highlight the code you want to run and click on the 'Run' button highlighted in red below. You can also type "Alt+Enter" on a widows keyboard.