Matthew Crump
10/31/2019
Let’s take the R Markdown quick tour from RStudio https://rmarkdown.rstudio.com/authoring_quick_tour.html
For a comprehensive guide to R Markdown see the definitive guide:
https://bookdown.org/yihui/rmarkdown/
and, a nice guide to basic markdown syntax: https://www.markdownguide.org/basic-syntax/
bells and whistles: https://holtzy.github.io/Pimp-my-rmd/
R Markdown is a good option for reproducible science.
R Markdown documents can contain all of the text for a manuscript, and all of the code used to run analyses and report results, all in one place.
Thus, if you share your research in R markdown, someone else should be able to reproduce exactly what you did.
Goals:
“YAML Ain’t Markup Language”
YAML is used to declare global parameters for the document.
This often includes title, author, bibliography files, and output formats.
There may be many more parameters depending on the template file used for the R Markdown document.
Set defaults for all R code chunks in setup chunk at the beginning
Defaults can be modified for individual chunks later on.
knitr
is the engine that converts .Rmd files to other file types. Each R code chunk is processed by knitr, and can take on options to control outputs.
echo=TRUE
sets the default to print all remaining code blocks to the output, FALSE
sets the default to not print the code blockswarning = FALSE
turns off printing of warningsmessage = FALSE
turns off printing of messages, these commonly occur when you load a package, where you receive a message that the package was loadedeval = FALSE
sets the default to NOT evaluate the code chunk as R Code. This will not run the code block, but the code block will still print if echo=TRUE
error=TRUE
normally the knit fails when there is an error in the code. If you set error=TRUE
the knit will complete, and return an error message for code blocks with errors.The following setup options are useful for figure output.
fig.width = 3
sets the default width in inches for all figuresfig.height = 3
sets the default height in inches for all figuresfig.path = "myfigs/"
defines folder where figure files will be saved. This will be relative to your current working directoydev = c("pdf", "png")
tells knitr to output both .png, and .pdf versions of the figure. The .pdf contains vector graphics, meaning the figure can be resized without pixelization.knitr::render()
function, pressing the knit button in RStudio is a built-in way to call the render
function for the current document.Pressing the play button might show the graph, but compiling fails when knitting the document?
ggplot()
occurs in chunk 1 before the package is loaded in chunk 2, causing an error.ggplot2
package may be loaded in the current R session, allowing it to run the first chunk.knitr::include_graphics("path/name.ext")
$\sum$
will be printed as \(\sum\)<p> paragraph element </p>
will be inserted as a new paragraph elementpapaja
recommendations here for installing latex https://crsh.github.io/papaja_man/introduction.html#software-requirementstinytex
package