class: center, middle, inverse, title-slide # Practical R: R Markdown ### Abhijit Dasgupta ### BIOF 339 --- layout: true <div class="my-header"> <span>BIOF339</span></div> </div> --- class: middle, center, inverse # RMarkdown ---  --- ## R Markdown .left-column30[ + There are some choices you might need to make + Document is like a paper + Presentation is like PowerPoint + Shiny is an interactive web app developed in R. May talk about it towards the end + Various packages also provide templates for RMarkdown documents ] .right-column30[  ] --- .left-column30[ + Elements on the right are output formats - Documents produce Word, PDF or HTML - Presentations produce PowerPoint, PDF, or HTML ] .right-column30[  ] --- ``` --- title: "Untitled" author: "Abhijit Dasgupta" date: "9/11/2019" output: html_document --- ``` This determines the title and author, and the output type. Typically don't modify the entry in `output` for now -- ````markdown ```{r cars} summary(cars) ``` ```` This is a code chunk. RMarkdown evaluates this chunk of code and replaces the code with the results. This code chunk happens to be named "cars". The naming is optional but useful. --- .pull-left[ ### RMarkdown ````markdown ```{r cars} summary(cars) ``` ```` ] .pull-right[ ### Results ```r summary(cars) ``` ``` speed dist Min. : 4.0 Min. : 2.00 1st Qu.:12.0 1st Qu.: 26.00 Median :15.0 Median : 36.00 Mean :15.4 Mean : 42.98 3rd Qu.:19.0 3rd Qu.: 56.00 Max. :25.0 Max. :120.00 ``` ] --- .pull-left[ ### RMarkdown ````markdown ```{r} library(tableone) # Use a package kableone(CreateTableOne(data=airquality), format='html') ``` ```` ] .pull-right[ ### Results ```r library(tableone) # Use a package kableone(CreateTableOne(data=airquality), format='html') ``` <table> <thead> <tr> <th style="text-align:left;"> </th> <th style="text-align:left;"> Overall </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> n </td> <td style="text-align:left;"> 153 </td> </tr> <tr> <td style="text-align:left;"> Ozone (mean (SD)) </td> <td style="text-align:left;"> 42.13 (32.99) </td> </tr> <tr> <td style="text-align:left;"> Solar.R (mean (SD)) </td> <td style="text-align:left;"> 185.93 (90.06) </td> </tr> <tr> <td style="text-align:left;"> Wind (mean (SD)) </td> <td style="text-align:left;"> 9.96 (3.52) </td> </tr> <tr> <td style="text-align:left;"> Temp (mean (SD)) </td> <td style="text-align:left;"> 77.88 (9.47) </td> </tr> <tr> <td style="text-align:left;"> Month (mean (SD)) </td> <td style="text-align:left;"> 6.99 (1.42) </td> </tr> <tr> <td style="text-align:left;"> Day (mean (SD)) </td> <td style="text-align:left;"> 15.80 (8.86) </td> </tr> </tbody> </table> ] <br> <br> The code chunk on the left gets **replaced** by the table on the right in your document ---  --- ## Inline code evaluation .pull-left[ ### RMarkdown The airquality data set has `` `r nrow(airquality)` `` observations The average ozone level is `` `r mean(airquality$Ozone)` `` parts per billion ] .pull-right[ ### Results The airquality data set has 153 observations The average ozone level is 42.1293103 `` parts per billion ]