<-3 x
Quarto Book Example
Research Computing Services, IS&T, Boston University
Markdown Cheatsheet
To learn more about Quarto books visit https://quarto.org/docs/books.
Text Formatting
Heading1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
This is a plain text.
If you want to start a new paragraph - add 2 space characters at the end of the line.
One star ( * ) or one underscore ( _ ) around the text make it italic.
Two stars or underscores - bold
superscript27
subscript: H2O
strikethrough
RMarkdown supports LaTeX syntax:
A Math formula surrounded by a dollar sign \(\sum_{i=1}^n X_i\) is inline with text.
When it is surrounded by two dollar signs, it is placed in a separate line: \[\sum_{i=1}^{n}\left( \frac{X_i}{Y_i} \right)\]
Multiple starts (3 or more) make a horizontal rule. Needs a blank line above and below:
Lists
Lists (both ordered and unordered) need a blank line first:
- unordered list item
- next item in the unordered list
- sub-item1
- sub-item2
- sub-item3
- sub-item7
- First item
- Second Item
- sub-item1
- sub-item2
Tables
Table Header | Second Header |
---|---|
cell 1 | cell 2 |
cell 3 | cell 4 |
:— text is left justified :–: text is centered —: text is right justified
Formatted Table example:
Sum Sq | Df | F value | Pr(>F) | ||
---|---|---|---|---|---|
(Intercept) | 42785 | 1 | 357.4672 | < 2.2e-16 | *** |
var1 | 451 | 1 | 3.7653 | 0.0582130 | . |
var2 | 2034 | 2 | 8.4980 | 0.0006926 | *** |
The number of “-” symbols for each column on the second line of the above table controls the column width in the output.
Note: It is much easier to generate this table using R code. We included it here just as an example of using RMarkdown syntax for table generation.
R Code
R code can be included inline with a text using single back ticks and a lower case letter r. For example, we can define a variable x and assign a value to it and then compute its square and use it in the text: 49.
We can also include code chunks. This can be done by pressing a green button with a letter “C”, or with the keyboard shortcut Ctrl + Alt + I (Command + Option + I):
library(tidyverse)
By default, both R chunk and its output are included in the resulting document. We will also see error and warning messages (if any).
We can control what is included in the output document using chunk options:
<- rnorm(100)
x1 print(mean(x1))
A comprehensive description of the chunk options can be found in “Dynamic Documents with R and knitr by Yihui Xie.
Below is a list of some options:
Option | Default Value | Description |
---|---|---|
eval | TRUE | Evaluate the code and include its results |
echo | TRUE | Display code along with its results |
warning | TRUE | Display warnings |
error | FALSE | Display errors |
message | TRUE | Display messages |
tidy | FALSE | Reformat code in a tidy way when displaying it |
results | “markup” | “markup”, “asis”, “hold”, or “hide” |
cache | FALSE | Whether to cache results for future renders |
comment | “##” | Comment character to preface results with |
fig.width | 7 | Width in inches for plots created in chunk |
fig.height | 7 | Height in inches for plots created in chunk |
The chunks option can be included on the first line, separated by a comma:
<- rnorm(100)
x1 print(mean(x1))
[1] 0.09470173
They can also be included into the chunk itself, using YAML format. Notice, that in the later case, we use column (:) symbol to assign the value and the logical value is specified using lower-case letters:
<- rnorm(100)
x1 print(mean(x1))
results option
results option can take one of 4 values: “markup”, “asis”, “hold”, or “hide”.
Below is the output of a chunk for each choice:
markup (regular output):
<- rnorm(100)
x1 print(mean(x))
[1] 7
asis (text output):
<- rnorm(100)
x1 print(mean(x))
[1] 7
hold (hold all pieces of text output in a chunk and flush them to the end of the chunk):
<- rnorm(100)
x1 print(mean(x1))
<- rnorm(100)
x2 print(mean(x2))
[1] 0.2201017
[1] 0.07170454
hide (hide text output):
<- rnorm(100)
x1 print(mean(x))