-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathR_Quarto.html
390 lines (364 loc) · 19.9 KB
/
R_Quarto.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.2.269">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="Solomon Chak">
<meta name="dcterms.date" content="2023-03-14">
<title>R Quarto</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{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; 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; } /* 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 { color: #008000; } /* 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 { color: #008000; font-weight: bold; } /* 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>
<script src="R_Quarto_files/libs/clipboard/clipboard.min.js"></script>
<script src="R_Quarto_files/libs/quarto-html/quarto.js"></script>
<script src="R_Quarto_files/libs/quarto-html/popper.min.js"></script>
<script src="R_Quarto_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="R_Quarto_files/libs/quarto-html/anchor.min.js"></script>
<link href="R_Quarto_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="R_Quarto_files/libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="R_Quarto_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="R_Quarto_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="R_Quarto_files/libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
</head>
<body>
<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<nav id="TOC" role="doc-toc" class="toc-active">
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#what-is-quarto" id="toc-what-is-quarto" class="nav-link active" data-scroll-target="#what-is-quarto"><span class="toc-section-number">1</span> What is Quarto?</a></li>
<li><a href="#starting-a-quarto-document" id="toc-starting-a-quarto-document" class="nav-link" data-scroll-target="#starting-a-quarto-document"><span class="toc-section-number">2</span> Starting a Quarto Document</a></li>
<li><a href="#metadata" id="toc-metadata" class="nav-link" data-scroll-target="#metadata"><span class="toc-section-number">3</span> Metadata</a></li>
<li><a href="#header-and-text" id="toc-header-and-text" class="nav-link" data-scroll-target="#header-and-text"><span class="toc-section-number">4</span> Header and Text</a></li>
<li><a href="#code-chunks" id="toc-code-chunks" class="nav-link" data-scroll-target="#code-chunks"><span class="toc-section-number">5</span> Code Chunks</a></li>
</ul>
</nav>
</div>
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title">R Quarto</h1>
</div>
<div class="quarto-title-meta">
<div>
<div class="quarto-title-meta-heading">Author</div>
<div class="quarto-title-meta-contents">
<p>Solomon Chak </p>
</div>
</div>
<div>
<div class="quarto-title-meta-heading">Published</div>
<div class="quarto-title-meta-contents">
<p class="date">March 14, 2023</p>
</div>
</div>
</div>
</header>
<section id="what-is-quarto" class="level1" data-number="1">
<h1 data-number="1"><span class="header-section-number">1</span> What is Quarto?</h1>
<blockquote class="blockquote">
<p>Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <a href="https://quarto.org" class="uri">https://quarto.org</a>.</p>
</blockquote>
<p>You can combine your R codes (any many common programming languages) and your annotation into a nicely formated html page or pdf file. Other similar tools including R Markdown and Jupyter Notebook serve similar functions.</p>
</section>
<section id="starting-a-quarto-document" class="level1" data-number="2">
<h1 data-number="2"><span class="header-section-number">2</span> Starting a Quarto Document</h1>
<p>On RStudio of <a href="posit.cloud">posit.cloud</a>, click File > New File > Quarto Document. You also click the “green +” button on the upper left.</p>
<p>Provide a title for the document (e.g., “R Review”) and the author name. Leave everything else as default.</p>
<div class="quarto-figure quarto-figure-left">
<figure class="figure">
<p><img src="Images/quarto_start.png" class="img-fluid figure-img" alt="Setting up a Quarto document" width="499"></p>
<p></p><figcaption class="figure-caption">Setting up a Quarto document</figcaption><p></p>
</figure>
</div>
<p>You will now have a new Quarto document that is showing the “Visual” editor. Click the “disk” button to save the document (e.g., as R_review). The extension of the file will be .qmd, which stands for Quarto Markdown.</p>
<div class="quarto-figure quarto-figure-left">
<figure class="figure">
<p><img src="Images/quarto%20start.png" class="img-fluid figure-img" alt="A new Quarto document" width="650"></p>
<p></p><figcaption class="figure-caption">A new Quarto document</figcaption><p></p>
</figure>
</div>
<p>Notice that the title and author that you entered in the last windows appears in a box. There are other elements such as titles, text, and “code chunks” where your R codes are shown. You can run those codes by clicking the green “play” button on the upper right.</p>
<p>Click the “Source” button on the upper left to show the source code that generates this visual editor. You will now see a more familiar R script interface. You can build your documents in either the Source or the Visual editors, but we will begin with the Visual editor since it gives us a better sense of what the final webpage will look like.</p>
<div class="quarto-figure quarto-figure-left">
<figure class="figure">
<p><img src="Images/quarto%20source%20editor.png" class="img-fluid figure-img" alt="Quarto source editor" width="670"></p>
<p></p><figcaption class="figure-caption">Quarto source editor</figcaption><p></p>
</figure>
</div>
<p>Now click “Render” on the top. It will render your .qmd document into a webpage.</p>
</section>
<section id="metadata" class="level1" data-number="3">
<h1 data-number="3"><span class="header-section-number">3</span> Metadata</h1>
<p>In the visual editor, the first element that are between “---” are the metadata. Notice that it looks a little different after rendering. Here’s where some global settings to the whole quarto document can be added.</p>
<p>For example, adding these will above the second “---” add the date (pulling it from R’s system date), add a floating table of content (toc), automatically number the sections (for two header depth), and set up the code chunk to wrap overflowing codes. Render the document again to see the effects.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>date<span class="sc">:</span> <span class="st">"`r Sys.Date()`"</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a>toc<span class="sc">:</span> true</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a>toc<span class="sc">-</span>depth<span class="sc">:</span> <span class="dv">1</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a>toc_float<span class="sc">:</span> true</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a>number<span class="sc">-</span>sections<span class="sc">:</span> true</span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a>number<span class="sc">-</span>depth<span class="sc">:</span> <span class="dv">2</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a>code<span class="sc">-</span>overflow<span class="sc">:</span> wrap</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>A lot more options can be set in the section. See <a href="https://quarto.org/docs/reference/formats/opml.html">here</a> for more information.</p>
</section>
<section id="header-and-text" class="level1" data-number="4">
<h1 data-number="4"><span class="header-section-number">4</span> Header and Text</h1>
<p>In the visual editor, if you begin a new with <code>#</code>, it will automatically set the line to be header level 1. If you begin with <code>##</code>, it will set the line to header level 2.</p>
<p>You can also highlight the text and use the top manual bar to set the header levels.</p>
<div class="quarto-figure quarto-figure-left">
<figure class="figure">
<p><img src="Images/header%20manual.png" class="img-fluid figure-img" alt="Header setting"></p>
<p></p><figcaption class="figure-caption">Header setting</figcaption><p></p>
</figure>
</div>
<p>Other lines without a # are set as normal text by default.</p>
<p>You can surround text by a pair of <code>`</code> to mark it as code. Or use <code>Ctrl + D</code> to set a highlighted text to be code.</p>
<p>You can insert images from a URL. You can also use a local file, but be award that the image file (ideally in a folder) will also need to be uploaded if you are hosting your html somewhere (e.g., <a href="https://pages.github.com/">GitHub Pages</a>).</p>
<p>You can insert a link by <code>Ctrl + K</code> .</p>
</section>
<section id="code-chunks" class="level1" data-number="5">
<h1 data-number="5"><span class="header-section-number">5</span> Code Chunks</h1>
<p>You can insert code chunks by <code>Ctrl + Alt + I</code> (Macs: <code>Cmd + Option + I</code>). A new box that begins with <code>{r}</code> will appear. This is where you will put your R code. You can run commands as if you are in a R script file.</p>
<p>There are a lot of settings that can be done on individual code chunks. There settings should appear within the <code>{ }</code> and be separated by <code>,</code>. All of these are R markdown settings, but many of them could be set as Quarto settings. See <a href="https://quarto.org/docs/computations/execution-options.html#output-options">here</a>.</p>
<p>Commonly used ones are:</p>
<ul>
<li><p><code>results = 'hide'</code> prevents the result to be shown in the rendered file. This is useful when you have results that are very long, but you could get away with using <code>%>% head()</code></p></li>
<li><p><code>message = FALSE</code> prevents messages to be shown in the rendered file. This is useful for loading libraries.</p></li>
<li><p><code>warning = FALSE</code> prevents warnings to be shown in the rendered file.</p></li>
<li><p><code>eval = FALSE</code> prevents code to run when rendering. But the code will still display.</p></li>
</ul>
<p>Figures related:</p>
<ul>
<li><p><code>fig.show = 'hide'</code> presents the figure to be shown. This is useful when you only want to show the code but not the resulting plot.</p></li>
<li><p><code>echo = FALSE</code> prevents code, but not the results from appearing in the rendered file. This is a useful way to embed figures without showing the codes.</p></li>
<li><p><code>fig.cap = "..."</code> adds a caption to graphical results.</p></li>
</ul>
<p>Special uses:</p>
<ul>
<li><p><code>collapse = TRUE</code> will display the code and the result together inside code chunk when rendered.</p></li>
<li><p><code>include = FALSE</code> prevents code and results from appearing in the finished file. R Markdown still runs the code in the chunk, and the results can be used by other chunks. This is a useful way to load a private dataset that you don’t want to make publish yet.</p></li>
</ul>
<p>Using Quarto setting (begins with <code>#|</code>), you can make the code (and results) hidden but expandable by readers.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>{r, collapse<span class="ot">=</span><span class="cn">TRUE</span>}</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="co">#| code-fold: true</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<section id="give-it-a-try-and-make-an-r-review-page" class="level2" data-number="5.1">
<h2 data-number="5.1" class="anchored" data-anchor-id="give-it-a-try-and-make-an-r-review-page"><span class="header-section-number">5.1</span> Give it a try and make an R review page!</h2>
</section>
</section>
</main>
<!-- /main column -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const clipboard = new window.ClipboardJS('.code-copy-button', {
target: function(trigger) {
return trigger.previousElementSibling;
}
});
clipboard.on('success', function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copied!");
let tooltip;
if (window.bootstrap) {
button.setAttribute("data-bs-toggle", "tooltip");
button.setAttribute("data-bs-placement", "left");
button.setAttribute("data-bs-title", "Copied!");
tooltip = new bootstrap.Tooltip(button,
{ trigger: "manual",
customClass: "code-copy-button-tooltip",
offset: [0, -8]});
tooltip.show();
}
setTimeout(function() {
if (tooltip) {
tooltip.hide();
button.removeAttribute("data-bs-title");
button.removeAttribute("data-bs-toggle");
button.removeAttribute("data-bs-placement");
}
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
});
function tippyHover(el, contentFn) {
const config = {
allowHTML: true,
content: contentFn,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start'
};
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
// use id or data attribute instead here
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
return note.innerHTML;
});
}
const findCites = (el) => {
const parentEl = el.parentElement;
if (parentEl) {
const cites = parentEl.dataset.cites;
if (cites) {
return {
el,
cites: cites.split(' ')
};
} else {
return findCites(el.parentElement)
}
} else {
return undefined;
}
};
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const citeInfo = findCites(ref);
if (citeInfo) {
tippyHover(citeInfo.el, function() {
var popup = window.document.createElement('div');
citeInfo.cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
}
});
</script>
</div> <!-- /content -->
</body></html>