--- title: "A simple rmarkdown example" author: "Wolfgang Viechtbauer" date: "`r format(Sys.time(), '%d %B, %Y')`" output: pdf_document: default word_document: default fig_caption: yes bibliography: references.bib --- # Introduction This is an example of a R markdown document. With some basic formating codes you can make text *italic* and **bold**. ## Subheading You can also easily make lists: * item 1 * item 2 * item 3 Or numbered lists: 1. item 1 2. item 2 3. item 3 ### Subsubheading This is a "subsubheading". ## Equations If you know some basic latex syntax, you can easily add equations to your document. Equations can appear as part of the regular text (e.g., if $x = 2$, then $x + 4 = 6$). Or you can have equations appear in their own line: $$\frac{1}{2} + \frac{3}{4} = \frac{5}{4}.$$ When you compile the document, the equations should be nicely rendered. ## Links Links can be created by simply pasting the URL into the document: https://rmarkdown.rstudio.com/. Or, you can make a string of text become a link. For example, [R markdown](https://rmarkdown.rstudio.com/). ## Embedding R Code Where it gets really cool is when you start embedding R code in your document. For example: ```{r} set.seed(1234) x <- runif(100, min=0, max=30) y <- 10 + .5*x + .3*x^2 + rnorm(100, mean=0, sd=25) res1 <- lm(y ~ x) res2 <- lm(y ~ x + I(x^2)) summary(res1) ``` ## Dynamically Generated Plots Using regular R code, you can create graphs, which then get automatically embedded in the document. ```{r, fig.width=7, fig.height=5} plot(x, y, pch=19, xlab="Time in R Course", ylab="Your R Skills", main="R Skills as a Function of Time in Course") abline(res1, lty="dotted") lines(predict(res2, newdata=data.frame(x=seq(0,30,1)))) ``` You can also include the results from analyses in your text. For example, for the quadratic model, we find $R^2 =$ `r round(summary(res2)$r.squared, 2)`. I think we should send this article to Science or Nature! ## Tables You can also create tables from model objects (the `pander` package is very useful for that). ```{r, echo=FALSE, message=FALSE, warning=FALSE} if (!suppressWarnings(require(pander))) install.packages("pander") library(pander) ``` ```{r, echo=FALSE, results='asis'} pander(res2, caption="Results from Quadratic Model") ``` The `kable()` function from the `knitr` package can do something similar. ```{r, echo=FALSE, message=FALSE, warning=FALSE} if (!suppressWarnings(require(knitr))) install.packages("knitr") library(knitr) ``` ```{r, echo=FALSE, results='asis'} kable(round(coef(summary(res2)), 3), caption="Results from Quadratic Model") ``` These are just some of the basics. I hope you can see the potential here! ## References You can also include references. You need a bibliography file for this (see the `references.bib` file). For example, the first paper about the R language was written by @ihaka1996. Blah blah blah. We used R for the analyses [@r2020]. ## More Info To learn more about R Markdown, you should check out these websites: * [rmarkdown](https://rmarkdown.rstudio.com/) * [markdown](https://daringfireball.net/projects/markdown/) * [pandoc](https://pandoc.org/) These are some useful packages that can be useful when creating such documents. * [pander package](https://rapporter.github.io/pander/) * [xtable package](https://cran.r-project.org/package=xtable) * [texreg package](https://cran.r-project.org/package=texreg) # References