Open a new chunk code: shift + ctrl + i
or
echo
: Control the code displayCode executed & Shown
```{r}
#| echo: true
head(rock)
```
area peri shape perm
1 4990 2791.90 0.0903296 6.3
2 7002 3892.60 0.1486220 6.3
3 7558 3930.66 0.1833120 6.3
4 7352 3869.32 0.1170630 6.3
5 7943 3948.54 0.1224170 17.1
6 7979 4010.15 0.1670450 17.1
eval
& include
: Control the execution of the codeThe code is not executed (but it is shown)
```{r}
#| eval: false
#| echo: true
head(rock)
```
The code is executed, neither the code nor the results are show
```{r}
#| include: false
head(rock)
```
:::
warning: true
: (default) the warnings obtained from the code executed in the chunk are displayed message: true
: (default) the messages associated to the code (e.g., when you upload a package with library(package)
)
error: false
: (default) If there is an error in the code, knitting stops and the document will not be generated until the error is fixed
error: true
: If there is an error in the code, the error message is shown in the document and the knitting goes on
Defined in the YAML, they are applied to all code chunks unless otherwise specified:
If in one specific code we don’t want to display the code:
```{r}
#| echo: false
head(rock)
```
.png
and .jpg
@fig-peacock1 illustrates a peacock
Figure 1 illustrates a peacock
@fig-mtcars1 illustrates a plot
```{markdown}
#| out-width: 50%
#| fig-align: center
#| fig-cap: A graph from `mtcars`
#| fig-cap-location: bottom
#| label: fig-mtcars1
#| code-line-numbers: "|2|3|4|5|6"
ggplot(mtcars, aes(hp, mpg, color = factor(am))) +
geom_point() +
geom_smooth(formula = y ~ x, method = "loess") +
theme(legend.position = 'bottom')
```
Figure 2 illustrates a plot
mtcars
kable
Code chunks