class: title-slide, center, middle <span class="fa-stack fa-4x"> <i class="fa fa-circle fa-stack-2x" style="color: #ffffffcc;"></i> <strong class="fa-stack-1x" style="color:#3b4245;">04</strong> </span> # Data & Workflows ## R Markdown for Medicine ### Alison Hill · RStudio #### [rmd4medicine.netlify.com/](https://rmd4medicine.netlify.com/) --- class: middle, center # <i class="fas fa-cloud"></i> # Go here and log in (free): https://rstd.io/rmd4medicine-cloud --- layout: true <div class="my-footer"><span>https://rstd.io/rmd4medicine-cloud</span></div> --- class: middle, center, inverse <span class="fa-stack fa-4x"> <i class="fa fa-circle fa-stack-2x" style="color: #fff;"></i> <strong class="fa-stack-1x" style="color:#2f5275;">1 </strong> </span> -- # Hygiene --- class: middle, center # Philosophy -- .pull-left[ ### Less # ๐ญ ] .pull-right[ ### More # ๐น ] --- class: middle, center .pull-left[ ![](https://raw.githubusercontent.com/hadley/r4ds/master/screenshots/rstudio-workspace.png)<!-- --> ] .pull-right[ # <i class="fas fa-mouse-pointer"></i> In RStudio: _Tools > Global Options_ ] --- class: middle, center # Restart R early & often .pull-left[ # <i class="fas fa-mouse-pointer"></i> In RStudio: _Session > Restart R_ ] .pull-right[ # <i class="far fa-keyboard"></i> `Cmd/Ctrl` + `Shift` + `F10` (Mac) or `Ctrl` + `Shift` + `F10` (Windows/Linux) ] --- class: middle, center # Reknit up to... .pull-left[ # <i class="fas fa-mouse-pointer"></i> ![](images/rstudio-runabove.png) ] .pull-right[ # <i class="far fa-keyboard"></i> Place cursor anywhere in your doc then: `Command` + `Option` + `P` (Mac) or `Ctrl`+`Alt`+`P` (Windows/Linux) ] --- class: middle, center # <i class="fas fa-smoking-ban"></i> # Not recommended ```r rm(list = ls()) ``` .footnote[https://whattheyforgot.org/save-source.html#rm-list-ls] --- class: middle, center, inverse <span class="fa-stack fa-4x"> <i class="fa fa-circle fa-stack-2x" style="color: #fff;"></i> <strong class="fa-stack-1x" style="color:#2f5275;">2 </strong> </span> -- # Projects --- class: center, middle # R projects <img src="images/rproj.png" width="171" /> --- class: middle, center .pull-left[ # <i class="fas fa-mouse-pointer"></i> _File > New Project..._ <img src="images/rstudio-new.png" width="2056" /> ] -- .pull-right[ # <i class="fas fa-mouse-pointer"></i> Pick one <img src="images/rstudio-newproj.png" width="1773" /> ] --- class: middle, center # <i class="far fa-keyboard"></i> Equivalent to: _File > New Project...>_ New or Existing ```r library(usethis) create_project(here::here()) ``` .footnote[https://usethis.r-lib.org/reference/create_package.html] --- class: middle, center .pull-left[ # <i class="fas fa-mouse-pointer"></i> _File > New File > R Markdown..._ <img src="images/rstudio-newfile.png" width="2037" /> ] -- .pull-right[ # <i class="fas fa-mouse-pointer"></i> Fill in, can leave as HTML <img src="images/rstudio-newrmd.png" width="1768" /> ] --- class: middle, center .pull-left[ # <i class="fas fa-trash-alt"></i> ![](images/rstudio-freshrmd.png) ] -- .pull-right[ # <i class="fas fa-save"></i> ![](images/rstudio-blankrmd.png) ] --- class: live-code # Live code demo We make our first R project from scratch with a single R Markdown file inside. --- class: middle, center, inverse <span class="fa-stack fa-4x"> <i class="fa fa-circle fa-stack-2x" style="color: #fff;"></i> <strong class="fa-stack-1x" style="color:#2f5275;">3 </strong> </span> -- # External files --- class: center <img src="images/Data.jpg" width="1027" /> ??? save a local copy, keep raw data raw --- class: middle # File paths .pull-left[ ### <i class="far fa-thumbs-down"></i> ```r "~/mm/nope.csv" setwd("/haha/good/luck/") setwd('c:\iamyournightmare\!') setwd("C:\user\oh\no") setwd("path/that/only/works/on/my/machine") ``` ### <i class="far fa-thumbs-up"></i> ```r mockdata <- read_csv( here::here("data/mockdata.csv") ) ``` ] .pull-right[ <div class="figure" style="text-align: center"> <img src="images/horst_here.png" alt="Art by Allison Horst" width="90%" /> <p class="caption">Art by Allison Horst</p> </div> ] https://whattheyforgot.org/project-oriented-workflow.html#setwd --- class: middle, center, inverse <span class="fa-stack fa-4x"> <i class="fa fa-circle fa-stack-2x" style="color: #fff;"></i> <strong class="fa-stack-1x" style="color:#2f5275;">4 </strong> </span> -- # Bibliography --- See [citations](http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html#citations) .pull-right[ Generates these in-text citation styles: 1. Blah blah [see @R-blogdown, pp. 33-35; also @R-knitr, ch. 1]. 2. Blah blah [@R-blogdown, pp. 33-35]. 3. Blah blah [@R-blogdown; @R-knitr]. 4. Yihui says blah [-@R-blogdown]. 5. @R-blogdown says blah. ] --- class: your-turn # Your turn ### Choose your adventure 1. Take `04-manuscript.Rmd` and add in the tables and figures in code chunks, with code chunk options that make sense. ๐งถ __Knit__ and/or run chunks interactively as you work. 1. Play with knitting to different output formats. Try to figure out valid output options for each format you can add to your YAML. 1. Go to https://github.com/thomasp85/scico and try knitting with different palette names. Pick a favorite. __Too much?__ Look at `04-manuscript-alison.Rmd`, ๐งถ __Knit__. Then do 2 and 3 above. __Not enough?__ See next slide for building a graphical user interface for parameters.
15
:
00
--- class: your-turn # Your turn ### Extra: Play more with parameters .pull-left[ From `03-draft.Rmd` ```yaml --- params: palette: berlin --- ``` ] .pull-right[ Try in `04-manuscript.Rmd` ```yaml --- params: palette: input: select label: 'scico palette:' choices: - berlin - roma - cork - grayC selected: roma --- ``` ] --- # If we have time... .pull-left[ Open & Knit: `analyis/presentations/slides.Rmd` ```yaml --- output: beamer_presentation: slide_level: 2.0 powerpoint_presentation: default revealjs::revealjs_presentation: default --- ``` ] .pull-right[ ![](04-data-workflows_files/figure-html/unnamed-chunk-17-1.gif)<!-- --> ] --- class: middle, center, inverse # Time to wrap-up!
15
:
00
--- class: middle, center, inverse <span class="fa-stack fa-4x"> <i class="fa fa-circle fa-stack-2x" style="color: #fff;"></i> <strong class="fa-stack-1x" style="color:#2f5275;">!</strong> </span> # Extension formats --- class: middle, center # Dashboards <a href="https://jenthompson.me/examples/progressdash.html" target="_blank"><img src="https://jenthompson.me/images/flexdash_example.png" width="50%" /></a> https://jenthompson.me/examples/progressdash.html https://jenthompson.me/2018/02/09/flexdashboards-monitoring/ --- class: middle, center # Presentations <img src="04-data-workflows_files/figure-html/unnamed-chunk-20-1.gif" width="50%" /> https://bookdown.org/yihui/rmarkdown/presentations.html --- class: middle, center, inverse <span class="fa-stack fa-4x"> <i class="fa fa-circle fa-stack-2x" style="color: #fff;"></i> <strong class="fa-stack-1x" style="color:#2f5275;">!</strong> </span> # Cheatsheets! --- class: middle .left-column[ # ๐ ] .right-column[ _Help > Cheatsheets > RStudio IDE_ <a href="https://www.rstudio.com/resources/cheatsheets/#ide" target="_blank"><img src="https://442r58kc8ke1y38f62ssb208-wpengine.netdna-ssl.com/wp-content/uploads/2018/08/rstudio-ide.png" width="50%" /></a> ] .footnote[https://www.rstudio.com/resources/cheatsheets/#ide] --- class: middle .left-column[ # ๐ ] .right-column[ _Help > Cheatsheets > R Markdown Cheat Sheet_ <a href="https://www.rstudio.com/resources/cheatsheets/#rmarkdown" target="_blank"><img src="https://442r58kc8ke1y38f62ssb208-wpengine.netdna-ssl.com/wp-content/uploads/2018/08/rmarkdown-2.0.png" width="50%" /></a> ] .footnote[https://www.rstudio.com/resources/cheatsheets/#rmarkdown] --- class: middle .left-column[ # ๐ ] .right-column[ _Help > Cheatsheets > R Markdown Reference Guide_ <a href="https://www.rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf" target="_blank"><img src="https://442r58kc8ke1y38f62ssb208-wpengine.netdna-ssl.com/wp-content/uploads/2015/03/rmarkdown-reference-guide.png" width="40%" /></a> ] .footnote[https://www.rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf] --- class: middle, center, inverse <span class="fa-stack fa-4x"> <i class="fa fa-circle fa-stack-2x" style="color: #fff;"></i> <strong class="fa-stack-1x" style="color:#2f5275;">!</strong> </span> # Book! --- class: middle .left-column[ # ๐ ] .right-column[ <a href="https://bookdown.org/yihui/rmarkdown/" target="_blank"><img src="https://bookdown.org/yihui/rmarkdown/images/cover.png" width="40%" /></a> ] .footnote[https://bookdown.org/yihui/rmarkdown/] --- class: middle, center, inverse <span class="fa-stack fa-4x"> <i class="fa fa-circle fa-stack-2x" style="color: #fff;"></i> <strong class="fa-stack-1x" style="color:#2f5275;">!</strong> </span> # Websites! --- class: middle .left-column[ # ๐ ] .right-column[ <a href="https://rmarkdown.rstudio.com/" target="_blank"><img src="images/rmarkdown-site.png" width="80%" /></a> ] .footnote[https://rmarkdown.rstudio.com/] --- class: middle .left-column[ # ๐ ] .right-column[ <a href="https://rmarkdown.rstudio.com/docs/" target="_blank"><img src="images/rmarkdowndocs-site.png" width="80%" /></a> ] .footnote[https://rmarkdown.rstudio.com/docs/] --- class: middle .left-column[ # ๐ฏ ] .right-column[ <a href="https://community.rstudio.com/c/R-Markdown" target="_blank"><img src="images/rmarkdowncommunity-site.png" width="80%" /></a> ] .footnote[https://community.rstudio.com/c/R-Markdown] --- class: middle .left-column[ # ๐ค ] .right-column[ <a href="https://rmarkdown.rstudio.com/lesson-6.html" target="_blank"><img src="https://raw.githubusercontent.com/rstudio/rmarkdown/gh-pages/lesson-images/params-1-hawaii.png" width="80%" /></a> ] .footnote[https://bookdown.org/yihui/rmarkdown/parameterized-reports.html,<br> https://rmarkdown.rstudio.com/lesson-6.html] --- # More + [`redoc` ๐ฆ](https://noamross.github.io/redoc/) + [`spelling` ๐ฆ](https://docs.ropensci.org/spelling/) + [`wordcountaddin` ๐ฆ](https://github.com/benmarwick/wordcountaddin) --- class: inverse, middle, center # Thank you! Thanks to Peter Higgins & Daniel Chen for all their hard work