class: center, middle, inverse, title-slide # Tips for R Markdown ### David Selby ### 30
th
August 2017 --- ## Tabbed headers [![Tabset example](tabset.png)](tabset.html) ```markdown Header 1 {.tabset} ================== Subsection 1 ------------ Stuff Subsection 2 ------------ Bits ``` --- ### Printing lists of vectors ```r lst <- list(letters[1:3], letters[4:5], letters[6], letters[7:10]) ``` ``` ## [[1]] ## [1] "a" "b" "c" ## ## [[2]] ## [1] "d" "e" ## ## [[3]] ## [1] "f" ## ## [[4]] ## [1] "g" "h" "i" "j" ``` --- ### Printing lists of vectors ```r cat(sapply(c('', lst), function(x) paste(x, collapse = ', ')), sep = '\n- ') ``` - a, b, c - d, e - f - g, h, i, j ```r cat(sapply(c('', lst), function(x) paste(x, collapse = ', ')), sep = '\n1. ') ``` 1. a, b, c 1. d, e 1. f 1. g, h, i, j <!--Useful in an **rmdtools** package? e.g. `enumerate()`, `itemise()` or `listify(ordered = TRUE)`...--> --- ### Printing nice tables by default ```markdown output: html_document: df_print: kable ``` ```r head(iris) ``` <table> <thead> <tr> <th style="text-align:right;"> Sepal.Length </th> <th style="text-align:right;"> Sepal.Width </th> <th style="text-align:right;"> Petal.Length </th> <th style="text-align:right;"> Petal.Width </th> <th style="text-align:left;"> Species </th> </tr> </thead> <tbody> <tr> <td style="text-align:right;"> 5.1 </td> <td style="text-align:right;"> 3.5 </td> <td style="text-align:right;"> 1.4 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 4.9 </td> <td style="text-align:right;"> 3.0 </td> <td style="text-align:right;"> 1.4 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 4.7 </td> <td style="text-align:right;"> 3.2 </td> <td style="text-align:right;"> 1.3 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 4.6 </td> <td style="text-align:right;"> 3.1 </td> <td style="text-align:right;"> 1.5 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 5.0 </td> <td style="text-align:right;"> 3.6 </td> <td style="text-align:right;"> 1.4 </td> <td style="text-align:right;"> 0.2 </td> <td style="text-align:left;"> setosa </td> </tr> <tr> <td style="text-align:right;"> 5.4 </td> <td style="text-align:right;"> 3.9 </td> <td style="text-align:right;"> 1.7 </td> <td style="text-align:right;"> 0.4 </td> <td style="text-align:left;"> setosa </td> </tr> </tbody> </table> --- ## Errors, warnings and messages #### Bootstrap alerts - http://selbydavid.com/vignettes/alerts.html - [Example document](http://selbydavid.com/vignettes/statsclustering.html) #### testrmd package - https://github.com/ropenscilabs/testrmd - [Example document](https://ropenscilabs.github.io/testrmd/cranlogs_default.html) --- ## RStudio add-ins #### Word counts with `wordcountaddin` - <https://github.com/benmarwick/wordcountaddin> #### Insert citations with `citr` - <https://github.com/crsh/citr> #### Check grammar with `write-good` - <https://github.com/ropenscilabs/gramr> --- ## See also #### R Markdown Cheat Sheet - <https://www.rstudio.com/resources/cheatsheets/> #### These slides - <https://github.com/Selbosh/rmdtips> -- # Thank you!