# Creating a new script
## Option 1: File > New File > R Script
## Option 2: Top bar: white square with green plus icon
## Option 3: Ctrl+Shift+N (Win) Cmd+Shift+N (Mac)
## A new pane will be added to the RStudio window called the Source Editor
# Entering commands into script
## In the Source Editor, we can add many lines of code to a script
## This allows for longer and more complex operations
## Think of it like drafting an email with many instructions
(1.4 + 2.8 + 9.3) / 3
30.1 - 24.7
# Running one line of code
## Hitting Enter (Win) or Return (Mac) does not run the code
## We can run one line of code at a time to see its results in console
## Option 1: With cursor on a line, click the Run button (top-right)
## Option 2: With cursor on a line, Ctrl+Enter (Win) or Cmd+Return (Mac)
# Running many lines of code
## We can run multiple lines of code at once to see results in console
## Option 1: Highlight lines with mouse, click the Run button (top-right)
## Option 2: Highlight lines with mouse, Ctrl+Enter (Win) or Cmd+Return (Mac)
## We can even run all lines of code in a script at once
## Option 1: Click the Source button (top-right)
## Option 2: Ctrl+Shift+Enter (Win) or Cmd+Shift+Return (Mac)
# Adding comments to scripts
## To help communicate the purpose of our code, we can add comments
## Comments will be ignored by R and are only there for human readers
## We always start a comment in an R script with a hash symbol: #
## I have been using comments in this very section you are reading!
# Calculate the average score on the quiz
(1.4 + 2.8 + 9.3) / 3
# Calculate the difference between exam 1 and exam 2
30.1 - 24.7
100 / 9 # we can even have comments at the end of line (start will still run)
# Saving the script file
## Option 1: File > Save
## Option 2: Source bar: blue and white disk icon
## Option 3: Ctrl+S (Win) Cmd+S (Mac)
## For now, save it wherever; we'll learn about Projects soon
## You will now have a .R file that you can keep and/or transfer
## Only the code/input is saved in the script, not the results/output