Assumptions & Ground Rules

The purpose of this second assignment is to introduce you to working in RMarkdown. This will be the primary file format in which you will save and present your work for this class.

As noted previously, for this and all future assignments, you MUST type all commands in by hand. Do not copy & paste except for troubleshooting purposes (i.e., if you cannot figure out what you mistyped).

  • Early on, you may have a lot of trouble getting your code to run due to minor typos. This is normal.

  • Remember, you are learning to read and write a new (coding) language. As with learning any new languages, we learn from practice - and from correcting our mistakes.

Part 1 (Assignment 2.1)

Goal: Create new R Markdown file.

(Note: Remember that, when following instructions, always substitute “LastName” for your own last name and substitute YEAR_MO_DY for the actual date. E.g., Day_CRM495_RAssign2_2022_01_21)

In the first assignment, you learned about writing and running R code in an R Script file. You also saw how running certain commands (e.g., ggplot) from an R Script file will generate results in the RStudio Console. For Assignment 2, you will learn to create a new R Markdown file, and you will complete the remainder of your assignment in that file.

  • Like an R Script file, an R Markdown file can be used to write and run R code. However, an R Markdown file also can do much more than that. For instance, you can write and edit text, write and run R code, and generate statistical results and plots directly in the RMarkdown file. You can even create entire books and webpages using R Markdown. In fact, both this assignment and the first one were created using R Markdown.

  • R Markdown is an essential tool for producing reproducible research because, with it, we can thoroughly document and simultaneously provide detailed explanations for all of our coding decisions in a project - from opening and manipulating data, to recoding and combining variables, to summarizing and analyzing data, to creating and modifying figures.

  • We will start by simply opening and saving a new R Markdown file. For more detailed instructions, check out Danielle Navarro’s video series on using R Markdown.

  1. In RStudio, go to File > New File > R Markdown to open a new R Markdown document.
Opening a new R Markdown file

Opening a new R Markdown file

  1. The dialogue box asks for a Title, an Author, and a Default Output Format for your new R Markdown file.

    1. In the Title box, enter CRM 495: R Assignment 2.
    2. In the Author box, enter your First and Last Name (e.g., Jake Day).
    3. Under Default Output Format box, leave it as HTML which is usually the default selection.
  2. Click OK to create your new R Markdown file. It should look like this:

    Your new R Markdown file

    Your new R Markdown file

  3. The new R Markdown file contains a simple pre-populated template to show users how to do basic tasks like add settings, create text headings and text, insert R code chunks, and create plots. I recommend you read through the template the first time you open a new RMarkdown file as it contains useful information. However, it can also be a little overwhelming for new users. So we are going to delete everything after the metadata and second set of three dashes (i.e., after the YAML header).