8 Lesson 3: Basic Syntax
8.1 Heading Text
Heading text follows one or more hash-sign(s) (#). The number of hash-signs determines the hierarchy of headings. For example, “# Heading 1” would represent the primary heading, “## Heading 2” would represent the secondary heading, “### Heading 3” would represent the tertiary heading, and so forth.
8.2 Plain Text
Simply add text below the YAML header. To start a new paragraph, you will need to end your plain text line with two (2) spaces.
8.3 Bold and Italicized Text
There are two ways to format your text to be bold or italicized.
- Bold
- Surround your text with two (2) asterisks (*) on each side.
- Surround your text with two (2) underscores (_) on each side.
- Italicized
- Surround your text with one (1) asterisk (*) on each side.
- Surround your text with one (1) underscore (_) on each side.
The markdown syntax…
which renders to…
Bold Text Example
Bold Text Example
Italicize Text Example
Italicize Text Example
8.4 Lists
8.4.1 Unordered Lists
Unordered or bulleted lists can be generated by using a single asterisk (*) followed by a space and the plain text intended to represent the bullet. To add another bullet, just hit enter or return and follow the previous steps. To add sub-bullets, insert two spaces and a plus sign (+) followed by a space and the plain text intended to represent the sub-bullet. You can do this at multiple levels; meaning you can add four spaces and a plus sign (+) to insert a sub-sub-bullet and six spaces and a plus sign (+) to add a sub-sub-sub-bullet.
The markdown syntax…
which renders to…
- Bullet 1
- Bullet 2
- Sub-Bullet 1
- Sub-Bullet 2
- Sub-Sub-Bullet 1
- Sub-Sub-Bullet 2
8.4.2 Ordered Lists
Follow the steps in Unordered Lists but instead of using asterisk (*) use sequential numbers followed by a period (.)– this cannot be done for sub-bullets. For example, “1.”, “2.”, and “3.”.
The markdown syntax…
which renders to…
- Bullet 1
- Sub-Bullet 1
- Bullet 2
- Sub-Bullet 1
- Sub-Bullet 2
- Sub-Sub-Bullet 1
8.5 Link to a Section
You can link to a section within the document by surrounding the name of the section in square brackets.
The markdown syntax…
[Lesson 3: Basic Syntax]
would render to this…
If you click on the “Lesson 3: Basic Syntax” above, it will jump you to the head of this section.
8.6 Hyperlink
You simply need to paste in a full URL into your document and it will automatically be recognized as a hyperlink. For example…
https://bookdown.org/yihui/rmarkdown
If you want to hide the full link and represent it with text, then surround the text with square brackets followed by the URL in parenthesis.
The markdown syntax…
[link](https://bookdown.org/yihui/rmarkdown/)
would render to this…
link.
8.7 Insert Images
You can insert images into your document using syntax similar to the hyperlink syntax above.
In the code below you can see the file path the to the image. This image will render without a caption
![](images/hex_symbols/rmarkdown.png)
You can add a caption for the image in between the square brackets.
![This is my caption for the image.](images/hex_symbols/rmarkdown.png)
You can control the size of the image like this…
![This is my caption for the image.](images/hex_symbols/rmarkdown.png){width=200px}
You can center the image with HTML like this…
8.8 Tabbed Sections
Tabbed sections can be added to section of an HTML documents that will fold all of the subsequent sub-sections into separate tabs. To do this you specify a section header followed by {.tabset}
. For example, ## My Section Header {.tabset}
.
Note this feature is not available for use with bookdown.
8.9 Your Turn
- Using the .Rmd file created in Lesson 2: Rmd Creation, delete everything below the YAML header.
- Add the following level-1 headers and knit the document.
- Introduction
- Workflow
- Import Data
- Preprocessing
- Study Area
- Plot
- Conclusions
- Add two level-2 headers below the Plot header and knit the document.
- Scatter Plot
- LOESS Plot
- Add plain text below the Introduction header and knit the document.
- Be sure to include some bold and italicized text.
- Explain the purpose of the document (e.g., “This document was created during the 2020 NABs R Markdown workshop and will serve as an example workflow for my future use of R Markdown.”)
- Include the hyperlink to R Markdown: The Definitive Guide (https://bookdown.org/yihui/rmarkdown/). This will be a helpful resource in the future.
- Add unordered or ordered list below the Workflow header and knit the document.
- Describe the workflow we have talked about thus far (e.g., create an R project, add folders, create an rmarkdown document, knit the document to render).
- Add sub-bullets with helpful details.
- Add the image provided with the data to the Introduction.
- Make the Plot section tabbed section with
{.tabset}
.