class: center, middle, inverse # Automatic Reports with RMarkdown ### R Bootcamp for Scientific Computing 2020: Lecture 3 <b> <b> #### 2020/08/13 <img src="hex-stickers.png" width="70%" height="70%" /> --- background-image: url(https://github.com/rstudio/hex-stickers/blob/master/PNG/rmarkdown.png?raw=true) background-position: 95% 10% background-size: 20% # Overview ### 1. What is RMarkdown/Markdown? ### 2. "Knit" Scripts to Reports ### 3. My Favorite Packages Using RMarkdown --- # What is RMarkdown/Markdown? .center[ <img src="intro.png" width="100%" height="100%" /> ] --- # A .rmd file .right-column[ <img src="rmdfile.png" width="80%" height="80%" /> ] -- .left-column[ <b> <b> **YAML** "YAML Ain't Markup Language" <b> <b> <b> **TEXT** "Markdown language" **Code Chunk** ] --- class: inverse # Activity #1 (create a .rmd file) -- .center[ <img src="notebookinterface.png" width="90%" height="90%" /> ] --- background-image: url(https://github.com/rstudio/hex-stickers/blob/master/PNG/knitr.png?raw=true) background-position: 95% 10% background-size: 10% # Render output .pull-left[ ```r library(rmarkdown) render("***.Rmd") ``` ] .pull-right[ use the “**Knit**” button in the RStudio IDE ] -- ## How it works? .center[ <img src="rmarkdownflow.png" width="90%" height="90%" /> ] --- class: inverse # Activity #2 (render a .rmd file) -- .center[ <img src="renderfile.png" width="90%" height="90%" /> ] --- .right-column[ <img src="rmdfile.png" width="80%" height="80%" /> ] .left-column[ <b> <b> **YAML** "YAML Ain't Markup Language" <b> <b> <b> **TEXT** "Markdown language" **Code Chunk** ] --- background-image: url(markdown.png) background-position: 98% 5% background-size: 5% .panelset[ .panel[ .panel-name[Header] .pull-left[ ## Markdown text ```no-highlight # H1 ## H2 ### H3 #### H4 ##### H5 ###### H6 ``` ] .pull-right[ ## Rendered text # H1 ## H2 ### H3 #### H4 ##### H5 ###### H6 ] ] .panel[ .panel-name[Emphasis] .pull-left[ ## Markdown text ```no-highlight Italics, with *asterisks* or _underscores_. Bold, with **asterisks** or __underscores__. Combined emphasis with **asterisks and _underscores_**. Strikethrough uses two tildes. ~~Scratch this.~~ ``` ] .pull-right[ ## Rendered text Italics, with *asterisks* or _underscores_. Bold, with **asterisks** or __underscores__. Combined emphasis with **asterisks and _underscores_**. Strikethrough uses two tildes. ~~Scratch this.~~ ] ] .panel[ .panel-name[Lists] .pull-left[ ## Markdown text ```no-highlight 1. First ordered list item 2. Another item * Unordered sub-list. 1. Actual numbers don't matter, just that it's a number 1. Ordered sub-list 4. And another item. An indented paragraphs within list items. Asterisks Unordered list can use asterisks - Or minuses + Or pluses ``` ] .pull-right[ ## Rendered text 1. First ordered list item 2. Another item * Unordered sub-list. 1. Actual numbers don't matter, just that it's a number 1. Ordered sub-list 4. And another item. An indented paragraphs within list items. * Unordered list can use asterisks - Or minuses + Or pluses ] ] .panel[ .panel-name[Links] .pull-left[ ## Markdown text ```no-highlight [I'm an inline-style link](https://github.com/) [I'm an inline-style link with title](https://github.com/ "Github Homepage") [I'm an inline-style link with reference-style][1] [link text itself] URLs and URLs in angle brackets will automatically get turned into links. https://github.com or <https://github.com> [1]: https://github.com/ [link text itself]: https://github.com/ ``` ] .pull-right[ ## Rendered text [I'm an inline-style link](https://github.com/) [I'm an inline-style link with title](https://github.com/ "Github Homepage") [I'm an inline-style link with reference-style][1] [link text itself] URLs and URLs in angle brackets will automatically get turned into links. https://github.com or <https://github.com> [1]: https://github.com/ [link text itself]: https://github.com/ ] ] .panel[ .panel-name[Images] .pull-left[ ## Markdown text ```no-highlight Inline-style: ![alt text](https://logos-download.com/wp-content/uploads /2016/09/SpongeBob_SquarePants_picture_running.png "Logo Title Text 1") Reference-style: ![alt text][logo] [logo]: https://logos-download.com/wp-content/uploads/2016/09 /SpongeBob_SquarePants_picture_running.png "Logo Title Text 2" ``` ] .pull-right[ ## Rendered text Inline-style: ![alt text](https://logos-download.com/wp-content/uploads/2016/09/SpongeBob_SquarePants_picture_running.png "Logo Title Text 1") ] ] .panel[ .panel-name[Syntax] .pull-left[ ## Markdown text ```no-highlight Inline `code` has `back-ticks around` it. ``` <pre lang="no-highlight"><code>```javascript var s = "JavaScript syntax highlighting"; alert(s); <pre lang="no-highlight"><code>``` ```no-highlight ```python s = "Python syntax highlighting" print s ``` ``` ] .pull-right[ ## Rendered text <img src="inlinecode.png" width="80%" height="80%" /> ```javascript var s = "JavaScript syntax highlighting"; alert(s); ``` ```python s = "Python syntax highlighting" print s ``` ] ] .panel[ .panel-name[Blockquotes] .pull-left[ ## Markdown text ```no-highlight > I'm a quote in a block. ``` ] .pull-right[ ## Rendered text > I'm a quote in a block. ] ] .panel[ .panel-name[Tables] .pull-left[ ## Markdown text ```no-highlight Colons can be used to align columns. | Tables | Are | Cool | | ------------- |:-------------:| -----:| | col 3 is | right-aligned | $1600 | | col 2 is | centered | $12 | | zebra stripes | are neat | $1 | There must be at least 3 dashes separating each header cell. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown. Markdown | Less | Pretty --- | --- | --- `Still` | *renders* | **nicely** 1 | 2 | 3 ``` ] .pull-right[ ## Rendered text Colons can be used to align columns. | Tables | Are | Cool | | ------------- |:-------------:| -----:| | col 3 is | right-aligned | $1600 | | col 2 is | centered | $12 | | zebra stripes | are neat | $1 | There must be at least 3 dashes separating each header cell. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown. Markdown | Less | Pretty --- | --- | --- `Still` | *renders* | **nicely** 1 | 2 | 3 ] ] ] --- class: inverse # Activity #3 (write in Markdown) .panelset[ .panel[ .panel-name[Task] # Hello World (H1) ## This is a .md document (H2) Hi **Humans**! Jane Doe here, I like - Node.r ~~That's what I'm made of!~~ - Coffee.md I've had tacos on the moon and find them _far superior_ to Earth tacos. ] .panel[ .panel-name[Solution] ```no-highlight # Hello World (H1) ## This is a .md document (H2) Hi **Humans**! Jane Doe here, I like - Node.r ~~That's what I'm made of!~~ - Coffee.md I've had tacos on the moon and find them _far superior_ to Earth tacos. ``` ] ] --- .right-column[ <img src="rmdfile.png" width="80%" height="80%" /> ] .left-column[ <b> <b> **YAML** "YAML Ain't Markup Language" <b> <b> <b> **TEXT** "Markdown language" **Code Chunk** ] --- # Code Chunk #1 <img src="codechunk1.png" width="100%" height="100%" /> --- # Rendered Output #1 ```r # create leaflet graph library(leaflet) leaflet() %>% addTiles() %>% addMarkers(lng=-118.196980, lat=34.065764, popup="Soto Street Building.</br> No, no one is here.") ```
--- # Code Chunk #2 <img src="codechunk2.png" width="100%" height="100%" /> --- # Rendered Output #2
--- # Code Chunk #3 <img src="codechunk3.png" width="100%" height="100%" /> --- # Rendered Output #3 ```r # create leaflet graph library(leaflet) leaflet() %>% addTiles() %>% addMarkers(lng=-118.196980, lat=34.065764, popup="Soto Street Building.</br> No, no one is here.") ``` --- # Code Chunk #4 <img src="codechunk4.png" width="100%" height="100%" /> --- # Rendered Output #4 ```r # create leaflet graph library(leaflet) leaflet() %>% addTiles() %>% addMarkers(lng=-118.196980, lat=34.065764, popup="Soto Street Building.</br> No, no one is here.") ```
--- # Other language engines ```r names(knitr::knit_engines$get()) ``` ``` ## [1] "awk" "bash" "coffee" "gawk" "groovy" "haskell" ## [7] "lein" "mysql" "node" "octave" "perl" "psql" ## [13] "Rscript" "ruby" "sas" "scala" "sed" "sh" ## [19] "stata" "zsh" "asis" "asy" "block" "block2" ## [25] "bslib" "c" "cat" "cc" "comment" "css" ## [31] "ditaa" "dot" "embed" "exec" "fortran" "fortran95" ## [37] "go" "highlight" "js" "julia" "python" "R" ## [43] "Rcpp" "sass" "scss" "sql" "stan" "targets" ## [49] "tikz" "verbatim" "glue" "glue_sql" "gluesql" ``` -- .pull-left[ ### Code chunks <img src="engine.png" width="100%" height="100%" /> ] .pull-right[ ### Rendered output ```bash echo "Hello Bash!" ``` ``` ## Hello Bash! ``` ] --- .right-column[ <img src="rmdfile.png" width="80%" height="80%" /> ] .left-column[ <b> <b> **YAML** "YAML Ain't Markup Language" <b> <b> <b> **TEXT** "Markdown language" **Code Chunk** ] --- background-image: url(https://upload.wikimedia.org/wikipedia/commons/7/74/Zotero_logo.svg) background-position: 95% 10% background-size: 20% # Citr .pull-left[ `citr` provides functions and an RStudio addin to search a BibTeX-file to create and insert formatted Markdown citations into the current document. Github: https://github.com/crsh/citr ```r install.packages("citr") ``` or ```r devtools::install_github("crsh/citr") ``` **Better BibTeX integration** If you are using `Zotero`, you can install the Better BibTeX extension. Once the extension is installed, citr can access all your references and keep your bibliography file updated. ] .pull-right[ ![alt text](https://github.com/crsh/citr/raw/master/tools/images/addin_demo.gif) ] --- background-image: url(https://annakrystalli.me/talks/assets/logos/xaringan-hex.png) background-position: 95% 5% background-size: 10% # Xaringan .pull-left[ An R package for creating slideshows with `remark.js` through R Markdown. Github: https://github.com/yihui/xaringan ```r remotes::install_github('yihui/xaringan') ``` <iframe src="https://slides.yihui.org/xaringan/#1" width="80%" height="400px" data-external="1"></iframe> ] -- .pull-right[ ## xaringanExtra `xaringanExtra` is a playground of enhancements and extensions for xaringan slides. Github: https://github.com/gadenbuie/xaringanExtra ```r xaringanExtra::use_xaringan_extra(c("tile_view", "webcam")) ``` ] --- background-image: url(https://user-images.githubusercontent.com/163582/51942716-66be4180-23dd-11e9-8dbc-fdb4f465d1c2.png) background-position: 95% 5% background-size: 10% # pagedown .pull-left[ Github: https://github.com/rstudio/pagedown ![](https://user-images.githubusercontent.com/163582/46879762-7a34a500-ce0c-11e8-87e3-496f3577ff05.png) ] -- .pull-right[ <b> <b> <b> ![](https://user-images.githubusercontent.com/163582/47672385-e12dba00-db7f-11e8-92de-af94d5bab12f.jpg) ] --- background-image: url(https://github.com/mitchelloharawild/vitae/raw/master/man/figures/logo.png) background-position: 95% 5% background-size: 10% # vitae Github: https://github.com/mitchelloharawild/vitae ![](https://slides.mitchelloharawild.com/vitae/resources/twentyseconds.png) --- background-image: url(https://github.com/brentthorne/posterdown/raw/master/images/betterhexlogo.png) background-position: 95% 5% background-size: 10% # posterdown Github: https://github.com/brentthorne/posterdown Posterdown was created as a proof-of-concept that it is possible to make a beautiful poster using open source reproducible code. <img src="posters.png" width="100%" height="100%" /> --- --- background-image: url(https://camo.githubusercontent.com/0cab37d0a0a1237bc1fd97f41ceff51ce42f4444/68747470733a2f2f626f6f6b646f776e2e6f72672f79696875692f626c6f67646f776e2f696d616765732f6c6f676f2e706e67) background-position: 95% 5% background-size: 10% # blogdown Github: https://github.com/rstudio/blogdown Generate `static` websites based on `R Markdown` and `Hugo`. <img src="hugothemes.png" width="100%" height="100%" /> --- # Recommended readings - R Markdown: The Definitive Guide by Yihui Xie et al. [[link](https://bookdown.org/yihui/rmarkdown/)] - R Markdown Cheat Sheet [[link](https://github.com/rstudio/cheatsheets/raw/master/rmarkdown-2.0.pdf)] - Markdown Cheat Sheet [[link](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)] - R Markdown 10-minute tutorial [[link](https://commonmark.org/help/tutorial)] --- class: center, middle, inverse # Thanks for attending! 😄 ### Keep in touch @kerenxuepi