Chapter 3 R markdown

3.1 What is R markdown documents?

  • An R markdown document (a file with the extension .Rmd) allows us to create a report in a variety of formats (e.g., html, pdf, word, slides, interactive documents) that includes your codes, results, and texts.

  • An R markdown document is a plain text file with special formatting characters (i.e., Pandoc’s Markdown).

  • When you render an R markdown document using the render() function,

    • knitr executes all code chunks in an R markdown document to create a new markdown document (a file with the extension .md), and
    • pandoc (a universal document converter) converts a markdown document to the final format.

Rendering R markdown Document

  • An R markdown document has the following structure:
    • YAML header
      • YAML includes options for rendering
      • YAML is surrounded by - - -
      • YAML stands for “YAML Ain’t Markup Language”
    • Text
      • Text includes narration formatted with markdown
    • Code chunks
      • Code chunks include R Codes
      • Code chunks are surrounded by ```

3.3 RStudio Projects

3.4 Publish your R markdown Documents

3.5 Quiz 3

  • I uploaded the lecture video that I recorded for the previous semester. This semester, I am heavily updating the lecture notes of other topics. So I have been recording my lecture video again this semester according to my new lecture notes. However, I don’t have much things to update on the Rmarkdown part and so I just use the same lecture notes and lecture video.

  • The quiz 3 that you have to do in this week is different from HW2 in my previous lecture. So please ignore the HW2 in the lecture video.

  • The goal of this Quiz 3 is to check whether you can publish your contents using bookdown. In this way, you can communicate your findings with others. Please note that the ability to communicate with others is one of our important learning objective. I’m thinking to ask you to submit your final project in the form of this bookdown. So create a bookdown on the following the instructions in the lecture video and below, and send the URL (or link) of your published bookdown using the Google Form below.

  • When you edit your Rmarkdown, cheat sheet would be very useful. So, please visit here and download the cheat sheet for the Rmarkdown. In the cheat, there’s “Write with Markdown” section on the right side of the first page. That section shows the 1-1 correspondence between Rmarkdown and output. Check how each of the Rmarkdown syntax is converted into the output.

  • For Quiz 3, do the following:

    1. Following the instructions in the lecture video, create an a template bookdown and publish it on your own bookdown account.
    2. Replicate the 1.1 Welcome to the Course! and 1.2 Types of Data Analysis in our lecture notes with all text format (e.g., Bold fonts), hyperlink, image (I will upload the image file in the cyber campus), and tables. However, you don’t need to replicate the Datacamp code chunk in 1.1.
    3. Include your name at the top of the first page.
    4. (Very important) You should set your sharing settings as “Anyone - no login required” for TA to assess your bookdown for grading.
    5. Once you finish to publish your bookdown, please submit your name, student ID number, and bookdown URL using the following Google Form by Sep 26 23:59: