Get Started

Create a new R Markdown document from the File Menu

In RStudio…

  1. New File -> R Markdown -> Document ->PDF
  2. Generate some Literate Code
  3. Knit (Knit to PDF)

 

When inserting inline images, I find the following code works well for PDF documents via R Markdown:

knitr::include_graphics("images/pdf_05_newdoc.png") 

The challenge with PDF files is generating your tables with kintr::kable. There’s also a kableExtra package if you need more functionality with editing your tables.

knitr::kable(head(cars))
speed dist
4 2
4 10
7 4
7 22
8 16
9 10
knitr::kable(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

Including Plots

You can also embed plots, for example:

 
R We Having Fun Yet‽ -- Learning Series
Center for Data & Visualization Sciences
Duke University Libraries
John R Little

CC BY-NC