Chapter 4 Add text with Markdown

4.1 Headers

Headers are useful for organizing your document into sections, and with Markdown formatting you can have up to 6 types/sizes of headers. Use a # symbol before the label to create a new header.

Header 1

Header 2

Header 3

Header 4

Header 5
Header 6

The RStudio IDE has several features that are nice for R Markdown users. One is the drop-down code navigator in the bottom-left of your file editor as shown in Figure 4.1 (from the R for Data Science book).

RStudio code navigator

Figure 4.1: RStudio code navigator

As you can see, this uses your Markdown headers to allow you to navigate around your .Rmd file. You can also use the RStudio outline pane, as shown in Figure 4.2 (from the RStudio blog).

RStudio outline pane

Figure 4.2: RStudio outline pane

Your turn


Try using the RStudio code navigator or outline pane to see the outline for first_look.Rmd based on the Markdown headers. Use them to navigate to different sections in the document.

4.2 Text & Images

Let’s take a lightly-edited snippet from a blog post originally published on the Huffington Post in 2010, and show it in raw Markdown (L) and rendered (R).

How We Can Save Over 4 Million Children

Childhood vaccines are one of the great triumphs of modern medicine. Indeed, parents whose children are vaccinated no longer have to worry about their child’s death or disability from:

  • whooping cough,
  • polio,
  • diphtheria,
  • hepatitis, or
  • a host of other infections.

Vaccines are the most cost-effective health care interventions there are… We have three new, extremely effective vaccines to roll out in developing countries:

  1. pneumonia
  2. rotavirus
  3. meningitis A

By Ezekiel J. Emanuel, M.D., Ph.D.

Photo:

Receiving rubella vaccination, Brazil, 2008.

Your turn


Try using Markdown formatting to add some bold text or italics.
If this is easy, try creating numbered and unnumbered lists, or adding links or images.