class: center, middle, inverse, title-slide # R, RStudio, and RMarkdown --- background-image: url(https://www.r-project.org/logo/Rlogo.png) background-position: 85% 95% background-size: 200px ## R is ... - **Free** to use - **Extensible**: Over 15,000 user contributed add-on packages currently on CRAN! - **Powerful**: With the right tools, get more work done, faster. - **Flexible**: Not a question of *can*, but *how*. - **Frustrating**: Flexibility comes at a cost (easy to shoot yourself in the foot!). <br/> ```r # devtools::install_github("metacran/crandb") pkgs <- crandb::list_packages(limit = 999999) length(pkgs) ``` --- ## RStudio is ... RStudio is a convenient interface for R - an IDE, integreated development environment At its simplest: - R is like a car’s engine - RStudio is like a car’s dashboard <img src="images/engine-dashboard.png" width="1752" style="display: block; margin: auto;" /> Source: [Modern Dive](https://moderndive.com/) --- background-image: url("images/rstudio-panes.png") background-size: 900px background-position: 0% 90% ## The RStudio IDE --- ## The RStudio IDE 1. **Source editor:** Docking station for multiple files, Useful shortcuts ("Knit"), Highlighting/Tab-completion, Code-checking (R, HTML, JS), Debugging features 2. **Console window:** Highlighting/Tab-completion, Search recent commands 3. **Environment pane:** Tools for package development, git, etc 4. **Other tabs/panes:** Graphics, R documentation, File system navigation/access .footnote[ **LPT**: save yourself the headaches figuring out file paths and instead work in an RStudio R project (popup menu at the top left) ] --- ## Markdown - Markdown is a particular type of **markup** language. - Markup languages are designed to **produce documents from plain text**. - Some of you may be familiar with **LaTeX**. This is another (less human friendly) markup language for creating pdf documents. - LaTeX gives you much greater control, but it is restricted to pdf and has a much greater learning curve. - **Markdown** is becoming a **standard**. Many websites will generate HTML from Markdown (e.g. GitHub, Stack Overflow, reddit, ...). --- ## Markdown is easy ``` *italic* **bold** # Header 1 ## Header 2 ### Header 3 - List item 1 - List item 2 - item 2a - item 2b 1. Numbered list item 1 1. Numbered list item 2 - item 2a - item 2b ``` .footnote[ Have a look at RStudio's [RMarkdown cheat sheet](https://www.rstudio.com/resources/cheatsheets/) ] --- background-image: url(https://raw.githubusercontent.com/allisonhorst/stats-illustrations/master/rstats-artwork/rmarkdown_wizards.png) background-size: 600px background-position: 50% 105% ## What is RMarkdown? - ... an authoring format that enables easy creation of dynamic documents, presentations, and reports from R. - combines markdown syntax with embedded R code chunks that are run so their output can be included in the final document. - creates fully reproducible reports - each time you knit the analysis is ran from the beginning ??? - Code goes in chunks, defined by three backticks, narrative goes outside of chunks --- background-image: url("images/rmarkdown.png") background-size: 900px background-position: 0% 90% ## --- background-image: url(https://raw.githubusercontent.com/allisonhorst/stats-illustrations/master/rstats-artwork/rmarkdown_rockstar.png) background-size: 350px background-position: 95% 10% ## Why R Markdown? - **It's simple.** Focus on writing, rather than <br>debugging silly errors. - **It's flexible.** Markdown was created to <br>simplify writing HTML, but thanks to <br>pandoc, Markdown converts to many <br>different formats! - **It's dynamic.** Find a critical error? Get a <br>new dataset? Regenerate your report without copy/paste hell! - **Encourages transparency.** Collaborators (including your future self) will thank you for integrating your analysis & report. - **Enables interactivity/reactivity.** Allow your audience to explore the analysis (rather than passively read it). --- background-image: url("images/hello-rmarkdown.png") background-size: 900px background-position: 0% 90% --- class: yourturn .center[ # Your Turn (5 min) ] 1. Open RStudio, create a new project. 2. Create a new RMarkdown file and knit it. 3. Navigate to the RMarkdown cheat sheet and download a copy (Google for the link!) 4. Make changes to the markdown formatting and knit again. 5. Export output to different files. 6. If you feel adventurous, change some of the R code and knit again. --- ## Resources [Rstudio cheetsheet](https://github.com/rstudio/cheatsheets/raw/master/rstudio-ide.pdf) [Rmarkdown cheatsheet](https://github.com/rstudio/cheatsheets/raw/master/rmarkdown-2.0.pdf) [R Markdown Refernce Guide](https://www.rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf) Artwork by [@allison_horst](https://twitter.com/allison_horst?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor)