options(htmltools.dir.version = FALSE) # see: https://github.com/yihui/xaringan # install.packages("xaringan") # see: # https://github.com/yihui/xaringan/wiki # https://github.com/gnab/remark/wiki/Markdown options(width=110) options(digits = 4)
knitr::opts_chunk$set(comment=NA, fig.width=6, fig.height=6, echo = TRUE, eval = TRUE, message = FALSE, warning = FALSE, fig.align = 'center')
library(tidyverse) library(knitr)
.pull-left4[
A dynamic report is a document that contains key elements which are automatically accessed and/or created by code:
]
.pull-right4[
Example: http://rpubs.com/fabiorocha5150/decisiontreemodel
]
.pull-left3[
]
.pull-right3[
knitr::include_graphics("images/reproducibility_images.png")
]
.pull-left3[
Data, code, analyses, and plots are all interconnected.
The code must be correct because it is being run as the report is created.
Anyone, even your future self, can replicate your analyses.
If something changes in the data, the changes are automatically reflected in the results.
If you get new data, you can easily create new analyses.
]
.pull-right3[
]
.pull-left3[
]
.pull-right3[
knitr::include_graphics("images/RMarkdownOutputFormats.png")
]
Markdown is a simple, readible markup language that allows you to easily write text with special formatting tags, which are then converted to formatted outputs.
R Markdown is a combination of Markdown and R code.
knitr::include_graphics("images/markdown_ss.png")
knitr::include_graphics("images/markdown_cheat.png")
Source: https://www.rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf
knitr::include_graphics("images/openmarkdown.png")
knitr::include_graphics("images/markdown_example.png")
knitr::include_graphics("images/rmarkdown_ss2.png")
knitr::include_graphics("images/knitto.png")
http://rmarkdown.rstudio.com/gallery.html
knitr::include_graphics("images/chunkoptions.png")
ops_chunk$set()
. When you do, all future chunks will have these settings (unless you specify otherwise)# Example: Set default values for ALL future chunks # with knitr::ops_chunk$set knitr::opts_chunk$set(fig.width = 6, # Figure width (in) fig.height = 6, # Figure height (in) echo = TRUE, # Repeat code eval = TRUE, # Evaluate chunks message = FALSE, # Don't print messages warning = FALSE, # Don't print warnings fig.align = 'center') # Center figures
knitr::include_graphics("images/minichunk_ss_D.png")
knitr::include_graphics("images/minichunk_big_ss.png")
.pull-left3[
You can easily read in external files like images, R code, or datasets.
All external files should be in a folder in the "Root" Directory containing the Markdown (.Rmd) file
All data necessary for your report must be explicitly read into the document. So keep them close by!
]
.pull-right3[
dynamicreports.Rmd
that created this presentationknitr::include_graphics("images/rmarkdown_directory.png")
]
knitr
.pull-left3[
knitr::include_graphics("images/knitr_hex.png")
To render output like images and tables into R Markdown, use the knitr
package.
The two most useful knitr
functions are include_graphics()
and kable()
| Function|Output|
|:------|:----|
| include_graphics(path)
| Include an external image (e.g.; .png, .jpg)|
| kable(df, format)
|Include a dataframe as a table|
]
.pull-right3[
kable()
kable(economics[1:3, c("date", "pop")], format = 'markdown')
include_graphics(path = "images/rlogo.png")
]
.pull-left3[
When you "Knit" an R markdown document, it will start with an empty workspace (ie. it will forget everything!)
You must explicitly load all packages with library()
and load in external datasets (e.g.; clinical_data <- read_csv("data/data.csv")
)
If you have any typos, errors, or missing code, the document will not knit (this is a good thing!)
]
.pull-right3[
knitr::include_graphics("images/wellformattedmarkdown.png")
]
.pull-left3[
There are many different output formats you can create from an R Markdown document
Many come with RStudio, many are distributed in packages:
| Package|Description|
|:------|:----|
| xaringan
| Slideshows (like this one!)|
| papaja
|APA Manuscripts|
| rmdformats
|Many templates|
| prettydoc
|Many templates|
]
.pull-right3[
knitr::include_graphics("images/rmarkdown_templates.png")
]
.pull-left3[
In order to knit your document to a PDF, you'll need a TeX installation (you can install it for free: just Google 'Install TeX')
TeX is a much more advanced markup language. It's used in most scientific publications.
To create a PDF, Markdown is converted to LaTeX, which is then converted to a PDF document.
]
.pull-right3[
knitr::include_graphics("images/latex_collage.png")
]
.pull-left3[
The data, code, and output are all in the same place.
Everything works and is replicable! (If it wasn't, the document wouldn't Knit!)
You can produce great looking documents, from simple PDFs, to webpages, to presentations (like this one), to books.
]
.pull-right3[
knitr::include_graphics("images/markdown_complete.png")
]
.pull-left3[
If you want a fully contained, dynamic report that contains data, code, statistics, plots, text, help files and documentation that you can easily share, your answer may be creating an R Package.
# Install cStudy2017 from github install_github("bootcamp/cStudy2017") # Load cStudy2017 package library("cStudy2017") # Open cStudy2017 package help ?cStudy2017 # Oh study1_A contains study 1... ggplot(data = study1_A, ...) FFTrees(success ~ ., data = study1_A)
]
.pull-right3[
knitr::include_graphics("images/phillips2017_package_ss.png")
Read Wickham's book "R Packages" (also available for free online) to learn how to write your own package
]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.