-
Notifications
You must be signed in to change notification settings - Fork 7
02 Writing with R Markdown
Chapters in the Data Privacy Handbook are written as R Markdown (.Rmd) files.
R Markdown provides an authoring framework where you can easily combine text (markdown) and code (R) to generate high-quality documents that can be shared with an audience. These documents are fully reproducible and support dozens of static and dynamic output formats such as HTML, PDF, and Word. In our case, we use the HTML, PDF and Epub output formats, with the primary format being HTML.
An R markdown file consists of 2 types of content:
- Markdown: this is plain text with specific operators to indicate formatting. For example:
**a bold word**
will become a bold word, and[hyperlink text](a-link.org)
will become hyperlink text. - R code: some Rmd files in the Data Privacy Handbook contain block of R code. They can be recognized by
```{r}
in the beginning of the code block, ending with```
. R markdown will recognize this as executable code and execute the code before converting to the specified output(s).
Should you want to only work with R markdown: the latest versions of R Studio should have R Markdown pre-installed, but you can install the package manually using the following code:
install.packages("rmarkdown")
For guidance on how to get started with and use R Markdown effectively, see the documentation.
In short, the workflow is as follows:
- First of all, you want to load the
rmarkdown
package with the following command:library(rmarkdown)
. Note that this is not necessary to run when you work on the Data Privacy Handbook as the dependencies should already be loaded by default. - Edit your .Rmd file
- Click the Knit button in RStudio to render the file and preview the output.
Markdown is a markup language to format text. You can check out the following links to familiarize yourself with the formatting, it's pretty straightforward!
- The R Markdown cheatsheet
- GitHub's Mastering Markdown Guide.