R Markdown can be regarded as simple text editor. You can write plain
text and format text elements by employing a simple in-text syntax. Set
your text as bold or in italics,
verbatim
or striked through, make
superscripts2 and subscripts2 or
combine
allthese.
When creating lists, make sure
Show special characters (escape) with a preceding “\”
Insert an extra line with \
For more options, please refer to the R Markdown Cheatsheet
In R Markdown, code chunks are the core elements that allow you to embed and run R (or other languages) directly within your document. They execute your analysis, create plots or tables, and generate results that can be automatically integrated into your text. Code chunks ensure that your report is reproducible, self-contained, and dynamically updated whenever the data or code changes. They form the bridge between narrative and computation, making R Markdown a powerful tool for transparent and efficient reporting.
A simple code chunk is reported both as code and result in the output document
1+3
## [1] 4
This default behavior can be altered by applying different chunk options. Here are the most prominent ones:
Suppress the display of code in the output document by using
echo=FALSE
## [1] 4
Exclude the entire chunk from the output document with
include=FALSE
Messages such as
x = TRUE
if (x) {
message("Approximation successful.")
}
## Approximation successful.
can be suppressed by employing message=FALSE
x = TRUE
if (x) {
message("Approximation successful.")
}
Similarly, to supress warnings such as
x <- -5
if (x < 0) {
warning("x is negative — results may be unreliable.")
}
## Warning: x is negative — results may be unreliable.
employ warning=FALSE
x <- -5
if (x < 0) {
warning("x is negative — results may be unreliable.")
}
In order to set selected chunk options as default for the document
you may add the opts_chunk$set()
function from the
knitr
package. The following code suppresses the display of
both code, messages, and warnings for the whole document:
```{r}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
```
Insert this code as first code chunk into your Markdown document if you prefer this behavior and alter the settings to your preferences where appropriate.