+ - 0:00:00
Notes for current slide
Notes for next slide

Lab 06: Building reports in R

1 / 9

Agenda

  • Knitting a pdf document
  • Creating tables in R
  • Lab 06: on your own
2 / 9

Knitting a pdf document

  • Currently your yaml at the top of your .Rmd files looks something like this:
---
title: "The title of your document"
name: "Your name"
output: html_document
---
3 / 9

Knitting a pdf document

What do you think you would change to render this as a pdf document instead of html?

  • Currently your yaml at the top of your .Rmd files looks something like this:
---
title: "The title of your document"
name: "Your name"
output: html_document
---
4 / 9

Knitting a pdf document

What do you think you would change to render this as a pdf document instead of html?

  • Currently your yaml at the top of your .Rmd files looks something like this:
---
title: "The title of your document"
name: "Your name"
output: pdf_document
---
5 / 9

Knitting a pdf document

What do you think you would change to render this as a pdf document instead of html?

  • Currently your yaml at the top of your .Rmd files looks something like this:
---
title: "The title of your document"
name: "Your name"
output: pdf_document
---
  • For this lab and your final project I want you to create .pdf files.
5 / 9

Making pretty tables

  • We've been using the tidy() and glance() functions to print tables of our model output.
  • These kind of look like "code" in our final reports
  • We can make these prettier with the knitr package
lm(wt ~ am, data = mtcars) %>%
tidy()
## # A tibble: 2 x 5
## term estimate std.error statistic p.value
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 (Intercept) 3.77 0.165 22.9 1.49e-20
## 2 am -1.36 0.258 -5.26 1.13e- 5
6 / 9

Making pretty tables

  • We've been using the tidy() and glance() functions to print tables of our model output.
  • These kind of look like "code" in our final reports
  • We can make these prettier with the knitr package
7 / 9

Making pretty tables

  • We've been using the tidy() and glance() functions to print tables of our model output.
  • These kind of look like "code" in our final reports
  • We can make these prettier with the knitr package
  • Load the knitr package with library(knitr)
  • Use the kable() function to output a pretty table
library(knitr)
lm(wt ~ am, data = mtcars) %>%
tidy() %>%
kable()
term estimate std.error statistic p.value
(Intercept) 3.768895 0.1646171 22.894914 0.00e+00
am -1.357895 0.2582726 -5.257603 1.13e-05
7 / 9

Putting all the R code at the end

  • For these fancy reports, we want to see the R code, but we don't want it intersperced throughout the document.
  • You can "hide" an R chunk by adding echo = FALSE to each of your chunks.
```{r, echo = FALSE}
```
  • You can "hide" all of your chunks by adding this to the top of your .Rmd file
library(knitr)
opts_chunk$set(echo = FALSE)
8 / 9

Putting all the R code at the end

  • For these fancy reports, we want to see the R code, but we don't want it intersperced throughout the document.
  • You can "hide" an R chunk by adding echo = FALSE to each of your chunks.
```{r, echo = FALSE}
```
  • You can "hide" all of your chunks by adding this to the top of your .Rmd file
library(knitr)
opts_chunk$set(echo = FALSE)
  • THEN at the end of you document (in the Appendix) you can add
```{r ref.label=knitr::all_labels(), echo = TRUE, eval = FALSE}
```
8 / 9

Open Lab 06: Building Reports in RStudio

9 / 9

Agenda

  • Knitting a pdf document
  • Creating tables in R
  • Lab 06: on your own
2 / 9
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow