RMarkdown
RMarkdown files are a mix of R scripts and Markdown documentation. They allow us to write documents and include R code inside.
Some documentation in Markdown...
```{r}
# some code in R
"Hello, World!"
```
You can also use LaTeX for formulas: $a+b = 2$.
The equation in this sentence will be centered $$a+b = 2$$
and take a whole line.
Where to learn? π₯
Inside editors, we are able to run the embedded snippets! π
Basic Overview
Metadata
We first define the header. It is used when generating a PDF or an HTML version of the .Rmd
.
---
title: 'blah blah'
output: html_document
---
To generate a PDF, you can use:
---
title: 'blah blah'
author: "blah blah"
date: " optional"
output:
pdf_document:
fig_caption: yes
html_document: default
fontsize: 11pt
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(error = TRUE)
knitr::opts_chunk$set(cache = TRUE)
knitr::opts_chunk$set(fig.align = "center")
knitr::opts_chunk$set(echo = TRUE, results="show")
```
[your document here]
We will then write LaTeX and Markdown content as usual.
R Code Blocs
Inside an editor, you can create a code block with CTRL+ALT+I
. We can use {r}
to configure the code block.
-
{r include = FALSE}
: code compiled but not shown -
{r echo = FALSE}
: code compiled but the code is not shown -
{r message = FALSE}
: code compiled but the result is not shown -
{r warning = FALSE}
: code compiled, do not show warnings -
{r error = FALSE}
: code compiled, do not show errors