4/22/2022

Familiar much?

So, what is this thing?

So, R Markdown was first created in 2014 a package (Allaire, Xie, McPherson, et al. 2022). Over the last few years, it’s become a fantastic resource to create documents where the code can live in line with text.

It was first introduced in the knitr package, with the idea to embed chunks of data (of R and other languages) into Markdown documents. However, in the past, it was overly simple and not suitable to writing very technical documents.

Thankfully, John MacFarlane created Pandoc, which converts these documents to different output formats, enriching the syntax.

Xie, Lesur, Thorne, and Tan (2022).

With R Markdown, you can:

  • Create a R Markdown document to a report in different formats, such as PDF, HTML, or Word.
  • Create notebooks in which you can directly run code chunks interactively.
  • Create slides for presentations (HTML5, LaTeX Beamer, or PowerPoint).
  • Produce dashboards with flexible, interactive, and attractive layouts.
  • Build Shiny apps.
  • Write journal articles.
  • Author books of multiple chapters.
  • Create websites and blogs.

Therefore…

There’s SO many things you can do with it!!! It’s so powerful and cool, and fun.

And, we’ve already seen it in action…

Examples of what you can do

Links to resources that are helpful

Installing it (if you don’t have it already)

To install, you can use the following code:

install.packages('rmarkdown')

Sometimes, to export certain outputs (PDFs, for example), you’ll need to download other packages in order to get certain things to function (tinytex, in this case).

Formatting

*italic* italic
**bold** bold
~~strikeout~~ strikeout
~subscript~ subscript
^superscript^ superscript
[small caps]{.smallcaps} small caps

As you can see above, all I did was put `’s between the code, and then you got the code inline with the actual text.

[link name](actual link)

Chunks

So, in R Markdown, we can have text like so, then we can also have chunks. These chunks are pieces of code that we embed into the document that actually do R things.

You do this by opening it with ```{r} and closing with 3 `.

Arguments in your Chunks

include = FALSE prevents code and results from appearing in the finished file. R Markdown still runs the code in the chunk, and the results can be used by other chunks.

echo = FALSE prevents code, but not the results from appearing in the finished file. This is a useful way to embed figures.

message = FALSE prevents messages that are generated by code from appearing in the finished file.

warning = FALSE prevents warnings that are generated by code from appearing in the finished.

fig.cap = “…” adds a caption to graphical results.

So, how does this work?

let’s see how it looks like! :)