-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathReadme.html
152 lines (150 loc) · 8.16 KB
/
Readme.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>Readme</title>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
</style>
<style type="text/css">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
{ position: relative; left: -4em; }
pre.numberSource a.sourceLine::before
{ content: attr(title);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; pointer-events: all; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
<div style="display: none">
\[
%%
% Add your macros here; they'll be included in pdf and html output.
%%
\newcommand{\R}{\mathbb{R}} % reals
\newcommand{\E}{\mathbb{E}} % expectation
\renewcommand{\P}{\mathbb{P}} % probability
\]
</div>
</head>
<body>
<h1 id="a-quick-introduction-to-rmarkdown">A quick introduction to R/markdown</h1>
<p>These are notes and materials for a short (2-hour) course on using R/markdown to generate reports and dynamic documents.</p>
<p>Here’s a link to <a href="http://petrelharp.github.io/r-markdown-tutorial/using-rmarkdown.slides.html">the slides</a>. Here is also a document with some <a href="http://petrelharp.github.io/r-markdown-tutorial/gotchas.html">gotchas</a> that I’ve figured out my way around, and some <a href="http://petrelharp.github.io/r-markdown-tutorial/technical-notes.html">technical notes</a> on getting pandoc, R+markdown, and this presentation to work.</p>
<h2 id="outline">Outline</h2>
<ol type="1">
<li><p>Markdown</p>
<ul>
<li>philosophy: just write</li>
<li>structure: headers, breaks</li>
<li>formatting: <strong>bold</strong>, <em>emphasis</em></li>
<li><a href="Outline">links</a></li>
<li>math</li>
<li>code blocks</li>
<li>images</li>
<li><a href="https://github.com/jgm/pandoc/issues/851">metadata</a></li>
<li>the <a href="http://en.wikipedia.org/wiki/Markdown">wider</a> <a href="http://blog.codinghorror.com/standard-flavored-markdown/">world</a> of <a href="http://commonmark.org/">markdown(s)</a></li>
</ul></li>
<li><p>Rendering markdown with <a href="http://pandoc.org">pandoc</a></p>
<ul>
<li>bare-bones</li>
<li>adding style</li>
<li>metadata/YAML headers</li>
<li>self-contained documents (+local mathjax)</li>
<li>gotchas</li>
<li>the <a href="http://pandoc.org/README.html">documentation</a> and <a href="http://stackoverflow.com/questions/tagged/pandoc?sort=frequent&pageSize=15">where to look for help</a></li>
</ul></li>
<li><p>Adding <a href="http://r-project.org/">R</a></p>
<ul>
<li>what <a href="http://yihui.name/knitr/">knitr</a> does</li>
<li>code chunks</li>
<li>figures</li>
<li>tables</li>
<li>chunk options</li>
<li>inline <code>R</code></li>
<li>rmarkdown and rstudio</li>
</ul></li>
<li><p>One report, many documents: a working example</p>
<ul>
<li>one subdirectory per dataset</li>
<li>json configuration + simulated data</li>
<li>external variables with knitr</li>
<li>using <code>Rscript</code> instead</li>
</ul></li>
</ol>
<h2 id="compiling-the-presentation-yourself">Compiling the presentation yourself</h2>
<p>The presentation uses <a href="http://lab.hakim.se/reveal-js/">reveal.js</a>. You can get this repository along with reveal.js like so:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><a class="sourceLine" id="cb1-1" title="1"><span class="fu">git</span> clone https://github.com/petrelharp/r-markdown-tutorial.git</a>
<a class="sourceLine" id="cb1-2" title="2"><span class="bu">cd</span> r-markdown-turoial</a>
<a class="sourceLine" id="cb1-3" title="3"><span class="fu">git</span> submodule init <span class="kw">&&</span> <span class="fu">git</span> submodule update</a></code></pre></div>
<p>With an up-to-date version of pandoc, R, and knitr, you should be able to compile the presentation like so:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><a class="sourceLine" id="cb2-1" title="1"><span class="fu">make</span> using-rmarkdown.slides.html</a></code></pre></div>
<p><em>Note:</em> OSX, for some reason, passes strings through make differently, so you need to uncomment a line in the Makefile, so it looks like this:</p>
<pre><code># or, uncomment for OSX:
KNITR_PATTERNS = list( chunk.begin="^```+\\\\s*\\\\{[.]?(r[a-zA-Z]*.*)\\\\}\\\\s*$$", chunk.end="^```+\\\\s*$$", inline.code="`r +([^`]+)\\\\s*`")</code></pre>
<p>(the only difference is an extra level of escaping the slashes).</p>
<p>Since I give presentations sometimes not on the internet, this by default relies on a local installation of MathJax, so unless you’ve installed this on Debian/Ubuntu (<code>aptitude install libjs-mathjax</code>), to view the maths properly you need to change the location in the Makefile.</p>
<p>The presentation will not render in Rstudio because: by default, <code>knitr</code> tries to process all code blocks; so to have example code in the document you have to munge your own code. To keep my document processable by just pandoc, and prettier (except the inline code) I am rendering the presentation after modifying the regular expression knitr uses to identify code chunks to require exactly three backticks, at the start of the line, and the identifier <code>r</code> (by default it is much more lax). See the Makefile for how this is done.</p>
</body>
</html>