#Lab 3: Generating Reports with R Markdown

Introduction

In this lab we learn how to integrate R code and text into a single report. We use the RMarkdown file format for this (.Rmd), which has many advantages:

Overall Goals

In this lab we will learn how to:

At the same time we will get a chance to practice the R commands we learned in the previous labs.

New R commands introduced in this lab: sum, panel.abline, ladd.

Creating an RStudio Project

RStudio projects allow us to organize our work. A project is essentially a folder/directory of related files. You can easily start a new project or download someone else’s project to start.

We have created a starting project for you. In order to set it up:

If all has gone well, you should now see the project files in the Files pane at the bottom right of RStudio.

The file we are interested in is called Lab3Report.Rmd. Click on it to open it up for editing. It should appear at the top left of the application window. We will work on this file in the subsequent sections.

Working with RMarkdown Documents

RMarkdown documents typically start with a header section. In it you get to specify title, author and date for the report, as well as some other technical settings that we will not worry about right now. Take a moment to add your own information in the header fields. Make sure to save your edits (File > Save) before proceeding. The rest of the RMarkdown document will contain the actual contents of your report.

Exporting an RMarkdown Document

Exporting an RMarkdown document into other formats is called Knitting. You will find a Knit pulldown at the top of the editing pane. Use the arrow to its right to select an output format.

DO NOW: Use Knit to HTML to create a compiled version of the report. You will need to do this frequently as you work on your report.

You will likely see a pop-up blocker dialog, click Try Again to have the output report show up on a new browser window. Make sure you have added your own title, name and date information to the header.

As this pop-up can get quite annoying after a while, you may wish to tell RStudio to instead show the output in the bottom right Viewer pane. To set that as the default behavior, go to Tools > Global Options ... > R Markdown > Show output preview in:, change that to “Viewer Pane” and click Apply and OK.

Completing the Lab

The first section of the Lab 3 report introduces R Code chunks, which are the way to combine our code with the report text. The subsequent sections contain the actual assignment, where you will be prompted to make statistical investigations and to document those investigations in the report. Follow those prompts to complete the assignment.

Submissions

When you are ready to submit: