Chapter 7 Creating your first script

A script can be broken down into a few layers which we are going to go through in detail, but here’s a general overview.

  1. Load/install required packages
  2. Load your data
  3. Perform data wrangling tasks
  4. Then what?
    1. create figures
    2. run statistics
    3. create tables
  5. Save outputs

Figures are saved in your /images directory, whereas the statistics and tables are saved in /data for future use. Each section is coded so that I can fold/unfold a given section. This allows me to only focus on the section of code that is important at that given point and time.

7.1 Headers

Before we get started you’ll see “Headers” throughout the script which are used to keep things organized. I use the following code within an .R file (not an .Rmd)

# Header 1 ----------
# ▐ Header 2 --------
# ▐ ▬ Header 3 --------