-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathR.html
317 lines (313 loc) · 21 KB
/
R.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<!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>Codebraid with R</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list[class]{list-style: none;}
ul.task-list li input[type="checkbox"] {
font-size: inherit;
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; 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 {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; }
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; }
code span.at { color: #7d9029; }
code span.bn { color: #40a070; }
code span.bu { color: #008000; }
code span.cf { color: #007020; font-weight: bold; }
code span.ch { color: #4070a0; }
code span.cn { color: #880000; }
code span.co { color: #60a0b0; font-style: italic; }
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; }
code span.do { color: #ba2121; font-style: italic; }
code span.dt { color: #902000; }
code span.dv { color: #40a070; }
code span.er { color: #ff0000; font-weight: bold; }
code span.ex { }
code span.fl { color: #40a070; }
code span.fu { color: #06287e; }
code span.im { color: #008000; font-weight: bold; }
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; }
code span.kw { color: #007020; font-weight: bold; }
code span.op { color: #666666; }
code span.ot { color: #007020; }
code span.pp { color: #bc7a00; }
code span.sc { color: #4070a0; }
code span.ss { color: #bb6688; }
code span.st { color: #4070a0; }
code span.va { color: #19177c; }
code span.vs { color: #4070a0; }
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; }
</style>
<style type="text/css">body {display: block;text-align: left;max-width: 40rem;padding-left: 0.5rem;padding-right: 0.5rem;margin: auto;}pre.numberSource a.sourceLine {position: relative;left: -3em;}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: 3em;color: #aaaaaa;}pre.numberSource {margin-left: 2em;border-left: 1px solid #aaaaaa;padding-left: 4px;}div.exampleMarkup:before{content: "Markdown";font-family: monospace;display: block;height: 2em;font-size: 150%;}div.exampleMarkup {padding-top: 0.5em;padding-left: 0.5em;padding-right: 0.5em;margin-top: 2em;margin-bottom: 1em;background-color: honeydew;border-style: solid;border-width: 1px;border-color: limegreen;border-radius: 0.2em;}div.exampleOutput:before{content: "Output";font-family: monospace;display: block;font-size: 150%;}div.exampleOutput {color: black;padding-top: 0.5em;padding-left: 0.5em;padding-right: 0.5em;margin-top: 1em;margin-bottom: 2em;background-color: whitesmoke;border-style: solid;border-width: 1px;border-color: lightgray;border-radius: 0.2em;}div.sourceCode {padding: 0.5em;background-color: aliceblue;border-style: solid;border-width: 1px;border-color: lightskyblue;border-radius: 0.2em;}div.exampleOutput div.sourceCode:before{content: "code";font-family: monospace;display: block;height: 2em;font-weight: bold;font-size: 120%;}pre.stdout:before{content: "stdout";display: block;height: 2em;font-weight: bold;font-size: 120%;}pre.stdout {color: black;padding: 0.5em;background-color: azure;border-style: solid;border-width: 1px;border-color: turquoise;border-radius: 0.2em;padding-left: 0.5em;}code.stdout {color: black;background-color: azure;border-style: solid;border-width: 1px;border-color: turquoise;}pre.stderr:before{content: "stderr";display: block;height: 2em;font-weight: bold;font-size: 120%;}pre.stderr {color: red;padding: 0.5em;background-color: lavenderblush;border-style: solid;border-width: 1px;border-color: pink;border-radius: 0.2em;padding-left: 0.5em;}code.stderr {color: red;background-color: lavenderblush;border-style: solid;border-width: 1px;border-color: pink;}pre.error:before{content: "Error";display: block;height: 2em;font-weight: bold;font-size: 120%;}pre.error {color: red;padding: 0.5em;background-color: lavenderblush;border-style: solid;border-width: 1px;border-color: pink;border-radius: 0.2em;padding-left: 0.5em;}code.error {color: red;background-color: lavenderblush;border-style: solid;border-width: 1px;border-color: pink;}</style>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<header id="title-block-header">
<h1 class="title">Codebraid with R</h1>
</header>
<h2 id="introduction">Introduction</h2>
<p>R code is executed with <code>Rscript</code>. The
<code>methods</code> library is loaded automatically by default as part
of the template into which user code is inserted. A null graphics
device, <code>pdf(file=NULL)</code>, is created by default to avoid the
automatic, unintentional creation of plot files with default names.
Saving plots requires explicit graphics commands.</p>
<h2 id="inline-code">Inline code</h2>
<h3 id="run">Run</h3>
<p>Inline code with <code>.cb-run</code> gives raw stdout.</p>
<div class="example">
<div class="exampleMarkup">
<pre><code>`cat(1 + 2)`{.R .cb-run}</code></pre>
</div>
<div class="exampleOutput">
<p>3</p>
</div>
</div>
<h3 id="expression-and-inline-notebook">Expression and inline
notebook</h3>
<p>Inline code with <code>.cb-expr</code> evaluates an expression and
then inserts the raw output into the document, where it is interpreted
as Markdown. Inline code with <code>.cb-nb</code> (<code>nb</code> is
short for <code>notebook</code>) is similar, except output is shown
verbatim. Expressions are converted to strings via
<code>toString()</code>.</p>
<div class="example">
<div class="exampleMarkup">
<pre><code>`paste("$2^8 = ", 2^8, "$", sep="")`{.R .cb-expr}</code></pre>
</div>
<div class="exampleOutput">
<p><span class="math inline">2<sup>8</sup> = 256</span></p>
</div>
</div>
<div class="example">
<div class="exampleMarkup">
<pre><code>`(x <- 1:20)[x %% 3 == 0]`{.R .cb-nb}</code></pre>
</div>
<div class="exampleOutput">
<p><code class="expr">3, 6, 9, 12, 15, 18</code></p>
</div>
</div>
<h3 id="stderr">Stderr</h3>
<p>In the event of an error, inline code automatically shows stderr by
default. This code is executed in its own session,
<code>inline_error</code>, so that it does not impact other
examples.</p>
<div class="example">
<div class="exampleMarkup">
<pre><code>`1 + "a"`{.R .cb-run session=inline_error}</code></pre>
</div>
<div class="exampleOutput">
<p><code class="stderr error">Error in 1 + "a" : non-numeric argument to binary operator Execution halted</code></p>
</div>
</div>
<h3 id="source-errors">Source errors</h3>
<p>A message is also displayed for errors in the Markdown source. This
usually includes the name of the document source and the approximate
line number.</p>
<div class="example">
<div class="exampleMarkup">
<pre><code>`cat(1 + 2)`{.R .cb-rn session=inline_source_error}</code></pre>
</div>
<div class="exampleOutput">
<p><code class="error sourceError">SOURCE ERROR in "R.cbmd" near line 52: Unknown or unsupported Codebraid command "cb-rn" SOURCE ERROR in "R.cbmd" near line 52: Missing valid Codebraid command</code></p>
</div>
</div>
<h2 id="block-code">Block code</h2>
<h3 id="run-1">Run</h3>
<p>Code blocks with <code>.cb-run</code> give raw stdout. There is
continuity between code blocks so long as they are in the same session;
variables persist.</p>
<div class="example">
<div class="exampleMarkup">
<pre><code>```{.R .cb-run session=hello}
x <- "Hello from *R!*"
```</code></pre>
</div>
</div>
<div class="example">
<div class="exampleMarkup">
<pre><code>```{.R .cb-run session=hello}
cat(x)
```</code></pre>
</div>
<div class="exampleOutput">
<p>Hello from <em>R!</em></p>
</div>
</div>
<h3 id="notebook">Notebook</h3>
<p>Code blocks with <code>.cb-nb</code> show the code and also the
verbatim stdout.</p>
<div class="example">
<div class="exampleMarkup">
<pre><code>```{.R .cb-nb session=random}
set.seed(1)
random_ints <- floor(runif(10, min=0, max=101))
cat("Random integers: ", random_ints, "\n\n")
summary(random_ints)
```</code></pre>
</div>
<div class="exampleOutput">
<div class="sourceCode" id="cb9" data-startFrom="1"><pre class="sourceCode numberSource R numberLines"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1"></a><span class="fu">set.seed</span>(<span class="dv">1</span>)</span>
<span id="cb9-2"><a href="#cb9-2"></a>random_ints <span class="ot"><-</span> <span class="fu">floor</span>(<span class="fu">runif</span>(<span class="dv">10</span>, <span class="at">min=</span><span class="dv">0</span>, <span class="at">max=</span><span class="dv">101</span>))</span>
<span id="cb9-3"><a href="#cb9-3"></a><span class="fu">cat</span>(<span class="st">"Random integers: "</span>, random_ints, <span class="st">"</span><span class="sc">\n\n</span><span class="st">"</span>)</span>
<span id="cb9-4"><a href="#cb9-4"></a><span class="fu">summary</span>(random_ints)</span></code></pre></div>
<pre class="stdout"><code>Random integers: 26 37 57 91 20 90 95 66 63 6
Min. 1st Qu. Median Mean 3rd Qu. Max.
6.00 28.75 60.00 55.10 84.00 95.00 </code></pre>
</div>
</div>
<p>While there is not yet support for automatically including plots when
using the built-in code execution system, including them manually is
straightforward. (Plots <em>are</em> included automatically when using
the <code>jupyter_kernel</code> option. See the documentation and
Jupyter example document.)</p>
<p>Note that this example uses the <code>show</code> keyword argument
for the code block so that the output is interpreted as raw Markdown
rather than displayed verbatim (the default for
<code>.cb-nb</code>).</p>
<div class="example">
<div class="exampleMarkup">
<pre><code>```{.R .cb-nb session=plot show=code+stdout:raw+stderr}
png("plot.png", width=500, height=350, bg="transparent")
x <- seq(0, 6, 0.01)
y <- sin(x)
plot(x, y, type="l", col="blue", lwd=3, xlab="x", ylab="y(x) = sin(x)")
invisible(dev.off())
markdown <- paste("![The function $y=\\sin(x)$]",
"(plot.png)",
"{width=100% max-width=500px}", sep="")
cat(markdown)
```</code></pre>
</div>
<div class="exampleOutput">
<div class="sourceCode" id="cb12" data-startFrom="1"><pre class="sourceCode numberSource R numberLines"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1"></a><span class="fu">png</span>(<span class="st">"plot.png"</span>, <span class="at">width=</span><span class="dv">500</span>, <span class="at">height=</span><span class="dv">350</span>, <span class="at">bg=</span><span class="st">"transparent"</span>)</span>
<span id="cb12-2"><a href="#cb12-2"></a>x <span class="ot"><-</span> <span class="fu">seq</span>(<span class="dv">0</span>, <span class="dv">6</span>, <span class="fl">0.01</span>)</span>
<span id="cb12-3"><a href="#cb12-3"></a>y <span class="ot"><-</span> <span class="fu">sin</span>(x)</span>
<span id="cb12-4"><a href="#cb12-4"></a><span class="fu">plot</span>(x, y, <span class="at">type=</span><span class="st">"l"</span>, <span class="at">col=</span><span class="st">"blue"</span>, <span class="at">lwd=</span><span class="dv">3</span>, <span class="at">xlab=</span><span class="st">"x"</span>, <span class="at">ylab=</span><span class="st">"y(x) = sin(x)"</span>)</span>
<span id="cb12-5"><a href="#cb12-5"></a><span class="fu">invisible</span>(<span class="fu">dev.off</span>())</span>
<span id="cb12-6"><a href="#cb12-6"></a>markdown <span class="ot"><-</span> <span class="fu">paste</span>(<span class="st">"![The function $y=</span><span class="sc">\\</span><span class="st">sin(x)$]"</span>,</span>
<span id="cb12-7"><a href="#cb12-7"></a> <span class="st">"(plot.png)"</span>,</span>
<span id="cb12-8"><a href="#cb12-8"></a> <span class="st">"{width=100% max-width=500px}"</span>, <span class="at">sep=</span><span class="st">""</span>)</span>
<span id="cb12-9"><a href="#cb12-9"></a><span class="fu">cat</span>(markdown)</span></code></pre></div>
<figure>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAAFeCAMAAABEjx0wAAAAe1BMVEX9/v0AAAAAADkAAGUAAP8AOY8AZrU5AAA5ADk5AGU5OWU5OY85ZrU5j9plAABlADllAGVlOQBlOY9lZmVlZrVltf2POQCPOTmPOWWPZgCPtY+P29qP2/21ZgC1ZmW1/rW1/v3ajzna/tra/v39tWX924/9/rX9/tr9/v1TWKblAAAAKXRSTlP/////////////////////////////////////////////////////AFL0IIcAAAqnSURBVHic7Z2NdtNGEEZxapLSQKC0CbQkhTT+e/8nrOUATWLJ2t2Z3ZnZ77un5/h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/+Km58ENXPvzmo5H0YecqO/6VHUjJnMsnJ1GnD8NvPwuOgo1278bn6Y+9Vl73/faSOV3hPF0y/L72eee7vCIHCKUDQumAUDoglA4IpQNC6YBQOiCUDgilA0LpgFA6IJQOCKUDQumAUDoglA4IpQNC6YBQOiCUDgilA0LpA3fSX+3HgtIHNh++Zt/6GRhKP3AvvSspFJR+QLCiQUAo/cDdH0BTOqUfWF/+K1sNIhaUvnu8/TBv1ZbYUDoglA4IpQNC6YBQOiCUDgilA0LpgFA6IJQOCKUDQumAUDoglA4IpQNC6YBQOiCUDsh/a7/Z4Kv/5kQAAAAASUVORK5CYII=" style="width:100.0%" data-max-width="500px" alt="The function y=\sin(x)" />
<figcaption aria-hidden="true">The function <span class="math inline"><em>y</em> = sin (<em>x</em>)</span></figcaption>
</figure>
</div>
</div>
<h3 id="stderr-1">Stderr</h3>
<p>Code blocks show stderr automatically by default.</p>
<div class="example">
<div class="exampleMarkup">
<pre><code>```{.R .cb-nb session=block_error}
var <- 123
cat(var)
flush(stdout())
var <- var + "a"
```</code></pre>
</div>
<div class="exampleOutput">
<div class="sourceCode" id="cb14" data-startFrom="1"><pre class="sourceCode numberSource R numberLines"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1"></a>var <span class="ot"><-</span> <span class="dv">123</span></span>
<span id="cb14-2"><a href="#cb14-2"></a><span class="fu">cat</span>(var)</span>
<span id="cb14-3"><a href="#cb14-3"></a><span class="fu">flush</span>(<span class="fu">stdout</span>())</span>
<span id="cb14-4"><a href="#cb14-4"></a>var <span class="ot"><-</span> var <span class="sc">+</span> <span class="st">"a"</span></span></code></pre></div>
<pre class="stdout"><code>123</code></pre>
<pre class="stderr error"><code>Error in var + "a" : non-numeric argument to binary operator
Execution halted</code></pre>
</div>
</div>
<h3 id="source-errors-1">Source errors</h3>
<p>A message is also displayed for errors in the Markdown source. This
usually includes the name of the document source and the approximate
line number.</p>
<div class="example">
<div class="exampleMarkup">
<pre><code>```{.R .cb-ruuun session=block_source_error}
cat(1 + 2)
```</code></pre>
</div>
<div class="exampleOutput">
<pre class="error sourceError"><code>SOURCE ERROR in "R.cbmd" near line 124:
Unknown or unsupported Codebraid command "cb-ruuun"
SOURCE ERROR in "R.cbmd" near line 124:
Missing valid Codebraid command</code></pre>
</div>
</div>
<h2 id="other-options">Other options</h2>
<p>By default, stdout and stderr are only shown if they are non-empty.
In some situations, it may be useful to represent empty output visually
as confirmation that there indeed was none.</p>
<div class="example">
<div class="exampleMarkup">
<pre><code>```{.R .cb-run show=code+stdout+stderr:verbatim_or_empty}
x <- 1 + 2
```</code></pre>
</div>
<div class="exampleOutput">
<div class="sourceCode" id="cb20" data-startFrom="1"><pre class="sourceCode numberSource R numberLines"><code class="sourceCode r"><span id="cb20-1"><a href="#cb20-1"></a>x <span class="ot"><-</span> <span class="dv">1</span> <span class="sc">+</span> <span class="dv">2</span></span></code></pre></div>
<pre class="stderr"><code> </code></pre>
</div>
</div>
<p>It is also possible to selectively hide output from a code chunk.</p>
<div class="example">
<div class="exampleMarkup">
<pre><code>```{.R .cb-nb hide=stdout}
cat(x)
```</code></pre>
</div>
<div class="exampleOutput">
<div class="sourceCode" id="cb23" data-startFrom="2"><pre class="sourceCode numberSource R numberLines"><code class="sourceCode r" style="counter-reset: source-line 1;"><span id="cb23-2"><a href="#cb23-2"></a><span class="fu">cat</span>(x)</span></code></pre></div>
</div>
</div>
<p><code>hide</code> takes any combination of <code>code</code>,
<code>stderr</code>, and <code>stdout</code>, or simply
<code>all</code>.</p>
</body>
</html>