Rmd on Rmd

Paul E. Johnson

Document Structure Overview

YAML Header

YAML = Yet Another Markdown Language

Style following that

Style guides & tipsheets

Daring Fireball: http://daringfireball.net/projects/markdown/syntax

RStudio Docs: https://support.rstudio.com/hc/en-us/articles/200486468-Authoring-R-Presentations

Converting documents to outputs

Understand the process

  1. User writes document in markdown, calls file “mgp.md” (my great presentation)

  2. A program, currently pandoc, is used to convert the document the user prepared into HTML, PDF, and so forth.
    1. Make an html slideshow in S5 format
      pandoc -t S5 mpg.md -o mgp.html
      
      2 . Make a PDF slideshow in beamer format
      pandoc -t beamer mgp.md -V theme:Warsaw -o mgp.pdf
      

See Producing slide shows with Pandoc by John Macfarlane, who has been a key contributor in the markdown movement.

  1. I tested many output formats in Ubuntu 14.10. Many formats available that are interesting, not all work well with my example document (more on that below)

Important take away point: Limitations

Now introduce R complication

That fills the same role as the Sweave chunk style.
<>=
rcode here
@

render equals knit + pandoc

  1. knit: convert Rmd to md The markdown file is run and the code chunks are–literally–replaced with R input and output.

    • Can be done in various ways. Most direct

      1
      R CMD knit mgp.Rmd
      2
      R -e "library(knitr); knit(\"mgp.Rmd\")"
  2. pandoc: convert the new md into HTML or PDF or whatnot

Do both steps at once

Tidbits about render

Working around gotchas

Can’t resize images that are imported with markdown

<img src="importfigs/Fumble-Chart-1.png" width="700" alt="Fumbles">

Chart asserting Patriots are Cheaters

Fumbles

slides too long for page

code lines too long

Cannot have R code chunk in 2 column format

Apparently unsolveable problem.

I hate double pound signs in output

Can be removed. It is discussed here http://stackoverflow.com/questions/15081212/remove-hashes-in-r-output-from-rmarkdown-and-knitr

Lets test that

dat <- data.frame(x1 = rnorm(100), y1 = rnorm(100))
print(dat)
           x1        y1
1   -0.024779 -0.532615
2   -0.595708 -0.065403
3   -0.679282 -0.175966
4    0.016064  1.250413
5   -0.063805 -0.508312
6   -1.608321 -0.618807
7   -0.841354 -1.166242
8   -0.343233  0.688238
9    0.969689  0.304409
10  -0.232601  0.298952
11  -0.326746  0.192090
12  -1.274201  0.470676
13   0.341392 -0.424203
14   0.402024 -0.568133
15   1.296188  0.488586
16  -0.050726 -1.180882
17   0.843548  0.286996
18   0.188009  0.958711
19  -1.230055  0.130812
20  -0.181701  0.108920
21   1.666027 -0.130299
22  -0.360731 -1.528802
23  -0.011685 -0.482568
24   2.405842 -0.463031
25   0.593297 -1.436603
26   0.605710 -1.723115
27  -0.530536 -2.544667
28  -0.047831 -0.384994
29  -0.179572 -0.837010
30  -0.246159  0.762408
31   0.273934  1.794685
32  -0.119660  0.110273
33  -0.595599 -0.247153
34   0.238085  0.768608
35   0.654706 -0.578918
36   1.134818 -0.652662
37   0.639108  0.733875
38  -0.692816  0.907084
39   0.486734 -1.450094
40   1.444495  0.836457
41   0.336546 -0.781412
42  -0.435300 -1.768317
43   1.881777 -0.381787
44   1.492625 -1.013744
45  -0.041094  0.126990
46  -2.897957 -0.262404
47   1.000007 -1.415912
48   0.850069  0.587383
49  -1.703858  0.337869
50  -0.651114 -2.093873
51   0.185027 -0.277187
52   2.250010 -1.325448
53   0.782664 -0.403607
54   0.024567  0.619302
55   1.197839 -1.828095
56   0.745664 -0.127138
57   0.734189 -0.051966
58   0.093099 -0.411510
59   0.530404 -1.059356
60   0.190963 -1.120711
61   0.227050  1.567924
62  -0.616940  0.141238
63   1.448590  0.895315
64  -2.031631  0.685063
65   1.264764 -0.538453
66   0.012714  2.189421
67   0.486739 -0.481019
68   2.371039 -1.239347
69   1.217416 -0.969725
70   0.785134 -0.763601
71   0.430800 -1.683312
72   1.530047  0.434939
73   0.003901  0.025294
74   0.209648 -0.565944
75  -1.425481 -0.012462
76  -0.420065  0.435284
77  -0.570460 -1.994284
78   0.024647 -0.097332
79  -0.203127 -2.010018
80  -0.095364 -0.153945
81  -0.557543  0.195889
82  -0.313085 -0.421158
83   0.344355  1.455487
84   0.339508  0.365507
85   0.373399 -0.348570
86   1.513025  0.458718
87  -0.244489 -1.520692
88  -1.850653 -0.290735
89  -1.288580  0.545778
90  -0.477307 -0.774239
91   1.522609 -0.001126
92   0.251029  1.831316
93  -0.636104  1.058433
94  -0.139130 -0.213064
95   0.450503  1.697548
96   0.262357  1.495269
97   0.282939  0.156782
98   0.252195  0.516725
99  -1.003409 -0.400118
100 -0.942661  0.013978

I want to save the fig files and insert them in my document