forked from rstudio/rmarkdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticles_report_from_r_script.html
348 lines (273 loc) · 11.1 KB
/
articles_report_from_r_script.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<title>Compiling Reports from R Scripts</title>
<script src="site_libs/header-attrs-2.3.7/header-attrs.js"></script>
<script src="site_libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/cosmo.min.css" rel="stylesheet" />
<script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<link href="site_libs/highlightjs-9.12.0/textmate.css" rel="stylesheet" />
<script src="site_libs/highlightjs-9.12.0/highlight.js"></script>
<meta name="description" content="Turn your analyses into high quality documents, reports, presentations and dashboards with R Markdown. Use a productive notebook interface to weave together narrative text and code to produce elegantly formatted output. Use multiple languages including R, Python, and SQL. R Markdown supports a reproducible workflow for dozens of static and dynamic output formats including HTML, PDF, MS Word, Beamer, HTML5 slides, Tufte-style handouts, books, dashboards, shiny applications, scientific articles, websites, and more." />
<link rel="icon" type="image/png" href="images/favicon.png" />
<script type="text/javascript" src="js/redirect.js"></script>
<script type="text/javascript" src="js/rmarkdown.js"></script>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-20375833-3', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['rstudio.com', 'rstudio.github.io', 'rviews.rstudio.com', 'community.rstudio.com', 'rpubs.rstudio.com', 'environments.rstudio.com', 'rstudio.org', 'dailies.rstudio.com', 'pages.rstudio.com', 'db.rstudio.com', 'solutions.rstudio.com', 'docs.rstudio.com', 'spark.rstudio.com', 'shiny.rstudio.com', 'education.rstudio.com', 'rstudio.cloud', 'shinyapps.io', 'team-admin.rstudio.com', 'blog.rstudio.com', 'support.rstudio.com', 'blogs.rstudio.com', 'keras.rstudio.com', 'swag.rstudio.com', 'tensorflow.rstudio.com', 'packagemanager.rstudio.com'] );
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<script type="text/javascript">
if (window.hljs) {
hljs.configure({languages: []});
hljs.initHighlightingOnLoad();
if (document.readyState && document.readyState === "complete") {
window.setTimeout(function() { hljs.initHighlighting(); }, 0);
}
}
</script>
<style type="text/css">
h1 {
font-size: 34px;
}
h1.title {
font-size: 38px;
}
h2 {
font-size: 30px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 18px;
}
h5 {
font-size: 16px;
}
h6 {
font-size: 12px;
}
.table th:not([align]) {
text-align: left;
}
</style>
<link rel="stylesheet" href="css/rmarkdown.css" type="text/css" />
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
</style>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
background: white;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before {
content: "";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "";
border: none;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
background-color: transparent;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<!-- code folding -->
</head>
<body>
<div class="container-fluid main-container">
<div id="rStudioHeader" class="alwaysShrunk">
<div class="innards bandContent">
<div>
<a class="productName" href="index.html">R Markdown</a>
<div class="rStudio"><span class="light">from </span> <a href="https://www.rstudio.com/"><div class="logo"></div></a></div>
</div>
<div id="menu">
<div id="menuToggler"></div>
<div id="menuItems">
<a class="menuItem" href="lesson-1.html">Get Started</a>
<a class="menuItem" href="gallery.html">Gallery</a>
<a class="menuItem" href="formats.html">Formats</a>
<a class="menuItem" href="articles.html">Articles</a>
<a class="menuItem" href="https://bookdown.org/yihui/rmarkdown/">Book</a>
<a class="menuItem" href="docs/">References</a>
<a class="menuItem gitHub" href="https://github.com/rstudio/rmarkdown"></a>
<a class="menuItem gitHubText" href="https://github.com/rstudio/rmarkdown">Source on GitHub</a>
</div>
</div>
</div>
</div>
<style type="text/css">
#TOC {
margin-left: 35px;
margin-top: 90px;
}
</style>
<script type="text/javascript">
$(".main-container").removeClass("main-container").removeClass("container-fluid").addClass("footerPushDown");
</script>
<div id="pageContent" class="standardPadding">
<div class="articleBandContent">
<div class="fluid-row" id="header">
<h1 class="title toc-ignore">Compiling Reports from R Scripts</h1>
</div>
<div id="overview" class="section level2">
<h2>Overview</h2>
<p>You don’t necessary need to author an R Markdown document to create a dynamic report. In fact, you can take any R script and compile it into a report that includes commentary, source code, and script output. Reports can be compiled to any output format including HTML, PDF, MS Word, and Markdown.</p>
<p>To compile a report from an R script you simply pass the script to render. For example:</p>
<pre class="r"><code>rmarkdown::render("analysis.R")
rmarkdown::render("analysis.R", "pdf_document")</code></pre>
<p>The first call to render creates an HTML document, whereas the second creates a PDF document.</p>
<p>If you are using RStudio then you can also create a report using the <em>Compile Report</em> command (Ctrl+Shift+K).</p>
</div>
<div id="metadata" class="section level2">
<h2>Metadata</h2>
<p>By default the name of the script, username, and current date and time are included in the header of the report You can override this default behavior by including metadata in a specially formatted R comment:</p>
<pre class="r"><code>#' ---
#' title: "Crop Analysis Q3 2013"
#' author: "John Smith"
#' date: "May 3rd, 2014"
#' ---</code></pre>
<p>You can also specify the output format within the metadata, for example:</p>
<pre class="r"><code>#' ---
#' title: "Crop Analysis Q3 2013"
#' output: pdf_document
#' ---</code></pre>
</div>
<div id="markdown-formatting" class="section level2">
<h2>Markdown Formatting</h2>
<p>Note that the R comment used above to add a title, author, and date includes a single-quote as a special prefix character. This is a <a href="https://cran.rstudio.com/web/packages/roxygen2/index.html">roxygen2</a> style comment, and it’s actually possible to include many such comments in an R script, all of which will be converted to markdown content within the compiled report. For example:</p>
<pre class="r"><code>#' A script comment that includes **markdown** formatting.</code></pre>
<p>Rather than displaying as an R comment in the compiled report any roxygen2 style comment will be treated as markdown and rendered accordingly.</p>
</div>
<div id="knitr-spin" class="section level2">
<h2>knitr Spin</h2>
<p>Including markdown within R comments is possible because <code>rmarkdown::render</code> calls the <a href="http://yihui.name/knitr/demo/stitch/"><code>knitr::spin</code></a> function to convert the R script to an Rmd file. The spin function also enables you to add knitr chunk options with another special comment prefix (<code>#+</code>). For example:</p>
<pre class="r"><code>#+ fig.width=5, fig.height=5
plot(cars)</code></pre>
<p>For more information on using spin see:</p>
<ul>
<li><p>Spin documentation: <a href="http://yihui.name/knitr/demo/stitch/" class="uri">http://yihui.name/knitr/demo/stitch/</a></p></li>
<li><p>Spin example: <a href="https://github.com/yihui/knitr/blob/master/inst/examples/knitr-spin.R" class="uri">https://github.com/yihui/knitr/blob/master/inst/examples/knitr-spin.R</a></p></li>
</ul>
<p>Note that when using <code>rmarkdown::render</code> the spin function is called automatically under the hood as part of rendering.</p>
</div>
</div> <!-- articleBandContent -->
</div> <!-- pageContent -->
<div id="rStudioFooter" class="band full">
<div class="bandContent">
<div id="copyright">© Copyright 2016 - 2020 RStudio, PBC</div>
<div id="logos">
<a href="https://twitter.com/rstudio" class="footerLogo twitter"></a>
<a href="https://github.com/rstudio" class="footerLogo gitHub"></a>
<a href="https://www.linkedin.com/company/rstudio-pbc" class="footerLogo linkedIn"></a>
<a href="https://www.facebook.com/rstudioinc/" class="footerLogo facebook"></a>
</div>
</div>
</div>
<!-- bizible -->
<script type="text/javascript" src="//cdn.bizible.com/scripts/bizible.js" async=""></script>
<!-- disqus -->
<div id="disqus_thread" class="standardPadding"></div>
<script type="text/javascript" src="js/disqus.js"></script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<script type="text/javascript" src="js/external-links.js"></script>
</div>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
$(document).ready(function () {
$('.tabset-dropdown > .nav-tabs > li').click(function () {
$(this).parent().toggleClass('nav-tabs-open')
});
});
</script>
<!-- code folding -->
</body>
</html>