class: center, middle, inverse, title-slide # R Markdown ## Rfun - An R Learning Series ### John Little ### 2020-03-10 --- exclude: TRUE --- class: bottom, center background-image: url(images/Rfun1.png) [Rfun](https://rfun.library.duke.edu): An R Learning Event .scriptsize[Part of the]<br> [Data & Visualization Services Workshop Series](https://library.duke.edu/data/workshops) --- ## Simplified Markup Language .pull-left[ - **Structure Document** for style and citations - **Literate Code** - Code Chunks - Inline Code + Prose - Multiple Code Langugages - Render in **many formats** ] .pull-right[.full-width[.content-box-blue[### Output Formats .small[ - .yellow[Slides] .scriptsize[(PowerPoint, **xaringan**, reveal, Beamer, Slidy, idoslides...)] - .yellow[Interactive Documents] .scriptsize[(HTML Widgets)] - .yellow[R Notebooks] - .yellow[Web Sites] .scriptsize[(**blogdown** & WebSites] - .yellow[Dashboards] - .yellow[MS Word Documents] - .yellow[E-books] .scriptsize[(bookdown, ePUB, Kindle)] - HTML documents - GitHub documents - RTF / ODT - **PDF** Documents - **Latex** .scriptsize[(ctex)] - Journal article templates .scriptsize[(e.g. elsevier journals)] - CV - Package Vignettes - More]]]] --- class: bottom background-image: url(images/rmarkdown.png) .footer-note[.tiny[.green[ Image Credit: [RStudio](https://rmarkdown.rstudio.com/) ]]] --- class: middle .pull-left[ .content-box-blue[**R Markdown in a nutshell**] ``` ## Sub-heading ### Another deeper heading Text attributes *italic*, **bold**, `monospace`. A [link](https://example.com). Bullet list: - apples - oranges - pears Numbered list: 1. apples 2. oranges 3. pears ``` ] .pull-right[ ## Sub-heading ### Another deeper heading *italicized*, **bold**, `monospace` A [link](https://google.com) Bullet list: - applies - oranges - pears Numbered list: 1. apples 2. oranges 3. pears ] .content-box-grey[.footnote[ 1. .footnotesize[[Introduction to R Markdown](https://rmarkdown.rstudio.com/articles_intro.html)] 1. .footnotesize[[R Markdown: The Definitive Guide](https://bookdown.org/yihui/rmarkdown/)] ]] --- ## YAML Header The YAML metadata affects the output of the rendered output. ``` yaml --- title: "R Notebook" subtitle: "Levering systemic power and smiling about it" author: "Wendy Byrde" date: "2018-09-28" abstract: "<i>Summary of my document.</i><p>" output: html_notebook --- ``` --- ## Resources - [R Markdown: The Definitive Guide](https://bookdown.org/yihui/rmarkdown/) book - [Rmarkdown.rstudio.com](https://Rmarkdown.rstudio.com/) - https://Rmarkdown.rstudio.com/gallery.html - [CheatSheets](https://rmarkdown.rstudio.com/lesson-15.html) - [Articles](https://rmarkdown.rstudio.com/articles.html) --- class: duke-orange, middle, center # But, Why R Markdown? --- class: middle, center ### Integration of R code chunks ### Easy to read & write ### Plain text is more [sustainable](https://programminghistorian.org/en/lessons/sustainable-authorship-in-plain-text-using-pandoc-and-markdown)<sup>1</sup> over time ### Multiple ouput formats .footnote[ 1. .scriptsize[https://programminghistorian.org/en/lessons/sustainable-authorship-in-plain-text-using-pandoc-and-markdown] ] --- .content-box-red[ ### Excercise 1 In RStudio, Open an R Notebook (`File > R Notebook`) and practice marking up your prose with at least three of the markdown elements below ] Style | Markdown Syntax --- | --- bold | `**bold**` italics | `*italics*` images | `![alt text](path/to/image)` web links | ` [Google](https://google.com)` ordered and unordered lists | cheetsheet - https://is.gd/rmarkdown tables | cheetsheet - https://is.gd/rmarkdown blockquotes | cheetsheet - https://is.gd/rmarkdown footnote | `My text to note^[my footnote]` --- .content-box-red[ ### Excercise 2 #### Literate Code: R Markdown with R code chunks In the same R Notebook add at least one of the markdown elements below ] Element / Documentation | Note --- | --- [Code Chunks](https://rmarkdown.rstudio.com/lesson-3.html) | **Ctrl + Alt + I** (OS X: Cmd + Option + I)<br>e.g. `plot(cars)` [Inline Code](https://rmarkdown.rstudio.com/lesson-4.html) | Insert code into prose: <br>e.g. \``r` `length(cars$speed)`\` [LaTex Equations](https://bookdown.org/yihui/rmarkdown/markdown-syntax.html#math-expressions) | bind LaTex within `$` <br>i.e. `$` equation `$`<br> e.g. `$\bar{X}=\frac{1}{n}\sum_{i=1}^nX_i$` [Chunk Options](https://bookdown.org/yihui/rmarkdown/r-code.html) | There are a lot of options. Try setting image size within the code chunk settings. ![](images/code_chunk_options.png) [YAML](https://ourcodingclub.github.io/2016/11/24/rmarkdown-1.html#identify) | Metadata and output options \` <!-- not sure why the preceeding needs to be here but otherwise next slide won't print --> --- .content-box-red[ ### Exercise 3 Choose an output format below and "get started" learning a new R Markdown output option ] Output Style | Instructions | Resources ------------ | ----------- | --------------------------------------- **Slide** Deck | [Get Started](../dukeslides_getstarted.html) | [DukeSlides](https://www.johnlittle.info/dukeslides/) (A [xaringan](https://slides.yihui.name/xaringan/#1) implementation) MS Word | [Get Started](../msword_getstarted.html) | Use `knitr::kable(df)` for [dataframe](https://bookdown.org/yihui/rmarkdown/html-document.html#data-frame-printing) printing Dashboard | [Get Started](../dashboards.html) | [flexdashboard](https://rmarkdown.rstudio.com/flexdashboard/) Website | [Get Started](../blogdown_getstarted.html) | [Blogdown](../blogdown_getstarted.html) PDF <br> <br> <br> | [Get Started](../pdf_getstarted.html) <br> <br> <br> | May need to install https://yihui.name/tinytex/<br> `install.packages('tinytex')` <br> `tinytex::install_tinytex()` Book <br> <br> <br> <br> | [Get Started](https://bookdown.org/yihui/bookdown/get-started.html) <br> <br> <br> <br> | [Bookdown](https://bookdown.org/yihui/bookdown/)<br>May need to install https://yihui.name/tinytex/<br> `install.packages('tinytex')` <br> `tinytex::install_tinytex()` --- # John Little .pull-left[.full-width[.content-box-green[ ### Data Science Librarian - https://johnlittle.info/ - https://github.com/libjohn ]] ### Rfun host... You can make **Rfun** with our resources for R and data science analytics. See the [R we having fun yet‽](https://rfun.library.duke.edu/) resource pages. ] .pull-right[.content-box-grey[ ### Duke University **Data & Visualization Services** - https://library.duke.edu/data/ - askData@Duke.edu - The /Edge, Bostock (1st Floor) - [Past Workshops](https://library.duke.edu/data/news/past-workshops) - [Guides & Tutorials](https://library.duke.edu/data/tutorials) ]] --- class: center, middle ## Shareable Data, presentation, and handouts <span class="cc"> <!-- Key: a: SA, b: BY, c: CC Circle, d: ND, n: NC, m: Sampling, s: Share, r: Remix, C: CC Full Logo --> C bn </span> [CC BY-NC license](https://creativecommons.org/licenses/by-nc/4.0/)