File: write2.html

package info (click to toggle)
r-cran-arsenal 3.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,784 kB
  • sloc: sh: 18; makefile: 5
file content (452 lines) | stat: -rw-r--r-- 55,308 bytes parent folder | download | duplicates (2)
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />

<meta name="viewport" content="width=device-width, initial-scale=1" />

<meta name="author" content="Ethan Heinzen" />


<title>The write2 function</title>

<script src="data:application/javascript;base64,Ly8gUGFuZG9jIDIuOSBhZGRzIGF0dHJpYnV0ZXMgb24gYm90aCBoZWFkZXIgYW5kIGRpdi4gV2UgcmVtb3ZlIHRoZSBmb3JtZXIgKHRvCi8vIGJlIGNvbXBhdGlibGUgd2l0aCB0aGUgYmVoYXZpb3Igb2YgUGFuZG9jIDwgMi44KS4KZG9jdW1lbnQuYWRkRXZlbnRMaXN0ZW5lcignRE9NQ29udGVudExvYWRlZCcsIGZ1bmN0aW9uKGUpIHsKICB2YXIgaHMgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yQWxsKCJkaXYuc2VjdGlvbltjbGFzcyo9J2xldmVsJ10gPiA6Zmlyc3QtY2hpbGQiKTsKICB2YXIgaSwgaCwgYTsKICBmb3IgKGkgPSAwOyBpIDwgaHMubGVuZ3RoOyBpKyspIHsKICAgIGggPSBoc1tpXTsKICAgIGlmICghL15oWzEtNl0kL2kudGVzdChoLnRhZ05hbWUpKSBjb250aW51ZTsgIC8vIGl0IHNob3VsZCBiZSBhIGhlYWRlciBoMS1oNgogICAgYSA9IGguYXR0cmlidXRlczsKICAgIHdoaWxlIChhLmxlbmd0aCA+IDApIGgucmVtb3ZlQXR0cmlidXRlKGFbMF0ubmFtZSk7CiAgfQp9KTsK"></script>
<link href="data:text/css,%0Aa%2Eanchor%2Dsection%20%7Bmargin%2Dleft%3A%2010px%3B%20visibility%3A%20hidden%3B%20color%3A%20inherit%3B%7D%0Aa%2Eanchor%2Dsection%3A%3Abefore%20%7Bcontent%3A%20%27%23%27%3B%7D%0A%2EhasAnchor%3Ahover%20a%2Eanchor%2Dsection%20%7Bvisibility%3A%20visible%3B%7D%0A" rel="stylesheet" />
<script src="data:application/javascript;base64,Ly8gQW5jaG9yIHNlY3Rpb25zIHYxLjAgd3JpdHRlbiBieSBBdHN1c2hpIFlhc3Vtb3RvIG9uIE9jdCAzcmQsIDIwMjAuCmRvY3VtZW50LmFkZEV2ZW50TGlzdGVuZXIoJ0RPTUNvbnRlbnRMb2FkZWQnLCBmdW5jdGlvbigpIHsKICAvLyBEbyBub3RoaW5nIGlmIEFuY2hvckpTIGlzIHVzZWQKICBpZiAodHlwZW9mIHdpbmRvdy5hbmNob3JzID09PSAnb2JqZWN0JyAmJiBhbmNob3JzLmhhc093blByb3BlcnR5KCdoYXNBbmNob3JKU0xpbmsnKSkgewogICAgcmV0dXJuOwogIH0KCiAgY29uc3QgaCA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3JBbGwoJ2gxLCBoMiwgaDMsIGg0LCBoNSwgaDYnKTsKCiAgLy8gRG8gbm90aGluZyBpZiBzZWN0aW9ucyBhcmUgYWxyZWFkeSBhbmNob3JlZAogIGlmIChBcnJheS5mcm9tKGgpLnNvbWUoeCA9PiB4LmNsYXNzTGlzdC5jb250YWlucygnaGFzQW5jaG9yJykpKSB7CiAgICByZXR1cm4gbnVsbDsKICB9CgogIC8vIFVzZSBzZWN0aW9uIGlkIHdoZW4gcGFuZG9jIHJ1bnMgd2l0aCAtLXNlY3Rpb24tZGl2cwogIGNvbnN0IHNlY3Rpb25faWQgPSBmdW5jdGlvbih4KSB7CiAgICByZXR1cm4gKCh4LmNsYXNzTGlzdC5jb250YWlucygnc2VjdGlvbicpIHx8ICh4LnRhZ05hbWUgPT09ICdTRUNUSU9OJykpCiAgICAgICAgICAgID8geC5pZCA6ICcnKTsKICB9OwoKICAvLyBBZGQgYW5jaG9ycwogIGguZm9yRWFjaChmdW5jdGlvbih4KSB7CiAgICBjb25zdCBpZCA9IHguaWQgfHwgc2VjdGlvbl9pZCh4LnBhcmVudEVsZW1lbnQpOwogICAgaWYgKGlkID09PSAnJykgewogICAgICByZXR1cm4gbnVsbDsKICAgIH0KICAgIGxldCBhbmNob3IgPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCdhJyk7CiAgICBhbmNob3IuaHJlZiA9ICcjJyArIGlkOwogICAgYW5jaG9yLmNsYXNzTGlzdCA9IFsnYW5jaG9yLXNlY3Rpb24nXTsKICAgIHguY2xhc3NMaXN0LmFkZCgnaGFzQW5jaG9yJyk7CiAgICB4LmFwcGVuZENoaWxkKGFuY2hvcik7CiAgfSk7Cn0pOwo="></script>

<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%;}
  div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
  ul.task-list{list-style: none;}
    </style>


<style type="text/css">code{white-space: pre;}</style>
<style type="text/css" data-origin="pandoc">
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 { } /* 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>
<script>
// apply pandoc div.sourceCode style to pre.sourceCode instead
(function() {
  var sheets = document.styleSheets;
  for (var i = 0; i < sheets.length; i++) {
    if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
    try { var rules = sheets[i].cssRules; } catch (e) { continue; }
    for (var j = 0; j < rules.length; j++) {
      var rule = rules[j];
      // check if there is a div.sourceCode rule
      if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") continue;
      var style = rule.style.cssText;
      // check if color or background-color is set
      if (rule.style.color === '' && rule.style.backgroundColor === '') continue;
      // replace div.sourceCode by a pre.sourceCode rule
      sheets[i].deleteRule(j);
      sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
    }
  }
})();
</script>



<link rel="stylesheet" href="data:text/css,body%20%7B%0Abackground%2Dcolor%3A%20%23fff%3B%0Amargin%3A%201em%20auto%3B%0Amax%2Dwidth%3A%20700px%3B%0Aoverflow%3A%20visible%3B%0Apadding%2Dleft%3A%202em%3B%0Apadding%2Dright%3A%202em%3B%0Afont%2Dfamily%3A%20%22Open%20Sans%22%2C%20%22Helvetica%20Neue%22%2C%20Helvetica%2C%20Arial%2C%20sans%2Dserif%3B%0Afont%2Dsize%3A%2014px%3B%0Aline%2Dheight%3A%201%2E35%3B%0A%7D%0A%23TOC%20%7B%0Aclear%3A%20both%3B%0Amargin%3A%200%200%2010px%2010px%3B%0Apadding%3A%204px%3B%0Awidth%3A%20400px%3B%0Aborder%3A%201px%20solid%20%23CCCCCC%3B%0Aborder%2Dradius%3A%205px%3B%0Abackground%2Dcolor%3A%20%23f6f6f6%3B%0Afont%2Dsize%3A%2013px%3B%0Aline%2Dheight%3A%201%2E3%3B%0A%7D%0A%23TOC%20%2Etoctitle%20%7B%0Afont%2Dweight%3A%20bold%3B%0Afont%2Dsize%3A%2015px%3B%0Amargin%2Dleft%3A%205px%3B%0A%7D%0A%23TOC%20ul%20%7B%0Apadding%2Dleft%3A%2040px%3B%0Amargin%2Dleft%3A%20%2D1%2E5em%3B%0Amargin%2Dtop%3A%205px%3B%0Amargin%2Dbottom%3A%205px%3B%0A%7D%0A%23TOC%20ul%20ul%20%7B%0Amargin%2Dleft%3A%20%2D2em%3B%0A%7D%0A%23TOC%20li%20%7B%0Aline%2Dheight%3A%2016px%3B%0A%7D%0Atable%20%7B%0Amargin%3A%201em%20auto%3B%0Aborder%2Dwidth%3A%201px%3B%0Aborder%2Dcolor%3A%20%23DDDDDD%3B%0Aborder%2Dstyle%3A%20outset%3B%0Aborder%2Dcollapse%3A%20collapse%3B%0A%7D%0Atable%20th%20%7B%0Aborder%2Dwidth%3A%202px%3B%0Apadding%3A%205px%3B%0Aborder%2Dstyle%3A%20inset%3B%0A%7D%0Atable%20td%20%7B%0Aborder%2Dwidth%3A%201px%3B%0Aborder%2Dstyle%3A%20inset%3B%0Aline%2Dheight%3A%2018px%3B%0Apadding%3A%205px%205px%3B%0A%7D%0Atable%2C%20table%20th%2C%20table%20td%20%7B%0Aborder%2Dleft%2Dstyle%3A%20none%3B%0Aborder%2Dright%2Dstyle%3A%20none%3B%0A%7D%0Atable%20thead%2C%20table%20tr%2Eeven%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0A%7D%0Ap%20%7B%0Amargin%3A%200%2E5em%200%3B%0A%7D%0Ablockquote%20%7B%0Abackground%2Dcolor%3A%20%23f6f6f6%3B%0Apadding%3A%200%2E25em%200%2E75em%3B%0A%7D%0Ahr%20%7B%0Aborder%2Dstyle%3A%20solid%3B%0Aborder%3A%20none%3B%0Aborder%2Dtop%3A%201px%20solid%20%23777%3B%0Amargin%3A%2028px%200%3B%0A%7D%0Adl%20%7B%0Amargin%2Dleft%3A%200%3B%0A%7D%0Adl%20dd%20%7B%0Amargin%2Dbottom%3A%2013px%3B%0Amargin%2Dleft%3A%2013px%3B%0A%7D%0Adl%20dt%20%7B%0Afont%2Dweight%3A%20bold%3B%0A%7D%0Aul%20%7B%0Amargin%2Dtop%3A%200%3B%0A%7D%0Aul%20li%20%7B%0Alist%2Dstyle%3A%20circle%20outside%3B%0A%7D%0Aul%20ul%20%7B%0Amargin%2Dbottom%3A%200%3B%0A%7D%0Apre%2C%20code%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0Aborder%2Dradius%3A%203px%3B%0Acolor%3A%20%23333%3B%0Awhite%2Dspace%3A%20pre%2Dwrap%3B%20%0A%7D%0Apre%20%7B%0Aborder%2Dradius%3A%203px%3B%0Amargin%3A%205px%200px%2010px%200px%3B%0Apadding%3A%2010px%3B%0A%7D%0Apre%3Anot%28%5Bclass%5D%29%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0A%7D%0Acode%20%7B%0Afont%2Dfamily%3A%20Consolas%2C%20Monaco%2C%20%27Courier%20New%27%2C%20monospace%3B%0Afont%2Dsize%3A%2085%25%3B%0A%7D%0Ap%20%3E%20code%2C%20li%20%3E%20code%20%7B%0Apadding%3A%202px%200px%3B%0A%7D%0Adiv%2Efigure%20%7B%0Atext%2Dalign%3A%20center%3B%0A%7D%0Aimg%20%7B%0Abackground%2Dcolor%3A%20%23FFFFFF%3B%0Apadding%3A%202px%3B%0Aborder%3A%201px%20solid%20%23DDDDDD%3B%0Aborder%2Dradius%3A%203px%3B%0Aborder%3A%201px%20solid%20%23CCCCCC%3B%0Amargin%3A%200%205px%3B%0A%7D%0Ah1%20%7B%0Amargin%2Dtop%3A%200%3B%0Afont%2Dsize%3A%2035px%3B%0Aline%2Dheight%3A%2040px%3B%0A%7D%0Ah2%20%7B%0Aborder%2Dbottom%3A%204px%20solid%20%23f7f7f7%3B%0Apadding%2Dtop%3A%2010px%3B%0Apadding%2Dbottom%3A%202px%3B%0Afont%2Dsize%3A%20145%25%3B%0A%7D%0Ah3%20%7B%0Aborder%2Dbottom%3A%202px%20solid%20%23f7f7f7%3B%0Apadding%2Dtop%3A%2010px%3B%0Afont%2Dsize%3A%20120%25%3B%0A%7D%0Ah4%20%7B%0Aborder%2Dbottom%3A%201px%20solid%20%23f7f7f7%3B%0Amargin%2Dleft%3A%208px%3B%0Afont%2Dsize%3A%20105%25%3B%0A%7D%0Ah5%2C%20h6%20%7B%0Aborder%2Dbottom%3A%201px%20solid%20%23ccc%3B%0Afont%2Dsize%3A%20105%25%3B%0A%7D%0Aa%20%7B%0Acolor%3A%20%230033dd%3B%0Atext%2Ddecoration%3A%20none%3B%0A%7D%0Aa%3Ahover%20%7B%0Acolor%3A%20%236666ff%3B%20%7D%0Aa%3Avisited%20%7B%0Acolor%3A%20%23800080%3B%20%7D%0Aa%3Avisited%3Ahover%20%7B%0Acolor%3A%20%23BB00BB%3B%20%7D%0Aa%5Bhref%5E%3D%22http%3A%22%5D%20%7B%0Atext%2Ddecoration%3A%20underline%3B%20%7D%0Aa%5Bhref%5E%3D%22https%3A%22%5D%20%7B%0Atext%2Ddecoration%3A%20underline%3B%20%7D%0A%0Acode%20%3E%20span%2Ekw%20%7B%20color%3A%20%23555%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%0Acode%20%3E%20span%2Edt%20%7B%20color%3A%20%23902000%3B%20%7D%20%0Acode%20%3E%20span%2Edv%20%7B%20color%3A%20%2340a070%3B%20%7D%20%0Acode%20%3E%20span%2Ebn%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Efl%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Ech%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Est%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Eco%20%7B%20color%3A%20%23888888%3B%20font%2Dstyle%3A%20italic%3B%20%7D%20%0Acode%20%3E%20span%2Eot%20%7B%20color%3A%20%23007020%3B%20%7D%20%0Acode%20%3E%20span%2Eal%20%7B%20color%3A%20%23ff0000%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%0Acode%20%3E%20span%2Efu%20%7B%20color%3A%20%23900%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%0Acode%20%3E%20span%2Eer%20%7B%20color%3A%20%23a61717%3B%20background%2Dcolor%3A%20%23e3d2d2%3B%20%7D%20%0A" type="text/css" />




</head>

<body>




<h1 class="title toc-ignore">The write2 function</h1>
<h4 class="author">Ethan Heinzen</h4>


<div id="TOC">
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#a-note-on-piping">A note on piping</a></li>
<li><a href="#examples-using-arsenal-objects">Examples Using <code>arsenal</code> Objects</a>
<ul>
<li><a href="#tableby"><code>tableby</code></a></li>
<li><a href="#modelsum"><code>modelsum</code></a></li>
<li><a href="#freqlist"><code>freqlist</code></a></li>
<li><a href="#comparedf"><code>comparedf</code></a></li>
</ul></li>
<li><a href="#examples-using-other-objects">Examples Using Other Objects</a>
<ul>
<li><a href="#knitrkable"><code>knitr::kable()</code></a></li>
<li><a href="#xtablextable"><code>xtable::xtable()</code></a></li>
<li><a href="#panderpander_return"><code>pander::pander_return()</code></a></li>
</ul></li>
<li><a href="#output-multiple-tables-to-one-document">Output Multiple Tables to One Document</a></li>
<li><a href="#output-other-objects-monospaced-as-if-in-a-terminal">Output Other Objects Monospaced (as if in a terminal)</a></li>
<li><a href="#add-a-yaml-header-to-the-output">Add a YAML Header to the Output</a></li>
<li><a href="#add-a-code-chunk-to-the-output">Add a Code Chunk to the Output</a></li>
<li><a href="#faqs">FAQs</a>
<ul>
<li><a href="#how-do-i-suppress-the-note-about-my-document-getting-rendered">How do I suppress the note about my document getting rendered?</a></li>
<li><a href="#how-do-i-look-at-the-temporary-.rmd-file">How do I look at the temporary <code>.Rmd</code> file?</a></li>
<li><a href="#how-do-i-prevent-my-document-from-being-rendered">How do I prevent my document from being rendered?</a></li>
<li><a href="#how-do-i-output-headers-raw-htmllatex-paragraphs-etc.">How do I output headers, raw HTML/LaTeX, paragraphs, etc.?</a></li>
<li><a href="#how-do-i-tweak-the-default-format-from-write2word-write2html-or-write2pdf">How do I tweak the default format from <code>write2word()</code>, <code>write2html()</code>, or <code>write2pdf()</code>?</a></li>
<li><a href="#how-do-i-output-to-a-file-format-other-than-word-html-and-pdf">How do I output to a file format other than word, HTML, and PDF?</a></li>
<li><a href="#how-do-i-avoid-prefixes-on-my-table-captions-in-pdf">How do I avoid prefixes on my table captions in PDF?</a></li>
<li><a href="#how-do-i-output-multiple-tables-with-different-titles">How do I output multiple tables with different titles?</a></li>
<li><a href="#why-is-write2-not-working-in-r-markdownr-studio">Why is <code>write2()</code> not working in R Markdown/R Studio?</a></li>
</ul></li>
</ul>
</div>

<div id="introduction" class="section level1">
<h1>Introduction</h1>
<p>The <code>write2*()</code> functions were designed as an alternative to SAS’s <code>ODS</code> procedure for useRs who want to save R Markdown tables to separate Word, HTML, or PDF files without needing separate R Markdown programs.</p>
<p>There are three shortcut functions for the most common output types: HTML, PDF, and Word. Each of these three functions calls <code>write2()</code>, an S3 function which accepts many file output types (see the help pages for <code>rmarkdown::render()</code>). Methods have been implemented for <code>tableby()</code>, <code>modelsum()</code>, and <code>freqlist()</code>, but also <code>knitr::kable()</code>, <code>xtable::xtable()</code>, and <code>pander::pander_return()</code>.</p>
<p>The two most important things to recognize with <code>write2()</code> are the following:</p>
<ol style="list-style-type: decimal">
<li><p>Which function is being used to output the object. Sometimes the <code>write2</code> functions use <code>summary()</code>, while other times they will use <code>print()</code>. The details for each object specifically are described below.</p></li>
<li><p>How the <code>...</code> arguments are passed. To change the options for the summary-like or print-like function, you can pass named arguments which will in turn get passed to the appropriate function. Details for each object specifically are described below.</p></li>
</ol>
</div>
<div id="a-note-on-piping" class="section level1">
<h1>A note on piping</h1>
<p><code>arsenal</code> is piping-compatible!</p>
<p>The <code>write2*()</code> functions are probably the most useful place to take advantage of the <code>magrittr</code> package’s piping framework, since commands are often nested several functions deep in the context of <code>write2*()</code>. Piping also allows the <code>arsenal</code> package to become a part of more standard analysis pipelines; instead of needing to write separate R Markdown programs, intermediate analysis tables and output can be easily incorporated into piped statements.</p>
<p>This vignette will sprinkle the foward pipe (<code>%&gt;%</code>) throughout as a hint at the power and flexibility of <code>arsenal</code> and piping.</p>
</div>
<div id="examples-using-arsenal-objects" class="section level1">
<h1>Examples Using <code>arsenal</code> Objects</h1>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(arsenal)</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(magrittr)</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="fu">data</span>(mockstudy)</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a>tmpdir <span class="ot">&lt;-</span> <span class="fu">tempdir</span>()</span></code></pre></div>
<div id="tableby" class="section level2">
<h2><code>tableby</code></h2>
<p>For <code>tableby</code> objects, the output function in <code>write2()</code> is <code>summary()</code>. For <code>summary.tableby</code> objects, the output function is <code>print()</code>. For available arguments, see the help pages for <code>summary.tableby()</code>. Don’t use the option <code>text = TRUE</code> with the <code>write2</code> functions.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>mylabels <span class="ot">&lt;-</span> <span class="fu">list</span>(<span class="at">sex =</span> <span class="st">&quot;SEX&quot;</span>, <span class="at">age =</span><span class="st">&quot;Age, yrs&quot;</span>)</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>tab1 <span class="ot">&lt;-</span> <span class="fu">tableby</span>(arm <span class="sc">~</span> sex <span class="sc">+</span> age, <span class="at">data=</span>mockstudy)</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="fu">write2html</span>(</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a>  tab1, <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.tableby.html&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>,</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a>  <span class="at">title =</span> <span class="st">&quot;My test table&quot;</span>,      <span class="co"># passed to summary.tableby</span></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a>  <span class="at">labelTranslations =</span> mylabels, <span class="co"># passed to summary.tableby</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a>  <span class="at">total =</span> <span class="cn">FALSE</span>                 <span class="co"># passed to summary.tableby</span></span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div>
</div>
<div id="modelsum" class="section level2">
<h2><code>modelsum</code></h2>
<p>For <code>modelsum</code> objects, the output function in <code>write2()</code> is <code>summary()</code>. For <code>summary.modelsum</code> objects, the output function is <code>print()</code>. For available arguments, see the help pages for <code>summary.modelsum()</code>. Don’t use the option <code>text = TRUE</code> with the <code>write2</code> functions.</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>tab2 <span class="ot">&lt;-</span> <span class="fu">modelsum</span>(alk.phos <span class="sc">~</span> arm <span class="sc">+</span> ps <span class="sc">+</span> hgb, <span class="at">adjust=</span> <span class="sc">~</span> age <span class="sc">+</span> sex, <span class="at">family =</span> <span class="st">&quot;gaussian&quot;</span>, <span class="at">data =</span> mockstudy)</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="fu">write2pdf</span>(</span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a>  tab2, <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.modelsum.pdf&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>,</span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a>  <span class="at">title =</span> <span class="st">&quot;My test table&quot;</span>, <span class="co"># passed to summary.modelsum</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a>  <span class="at">show.intercept =</span> <span class="cn">FALSE</span>,  <span class="co"># passed to summary.modelsum</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a>  <span class="at">digits =</span> <span class="dv">5</span>               <span class="co"># passed to summary.modelsum</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div>
</div>
<div id="freqlist" class="section level2">
<h2><code>freqlist</code></h2>
<p>For <code>freqlist</code> objects, the output function in <code>write2()</code> is <code>summary()</code>. For <code>summary.freqlist</code> objects, the output function is <code>print()</code>. For available arguments, see the help pages for <code>summary.freqlist()</code>.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>mockstudy[, <span class="fu">c</span>(<span class="st">&quot;arm&quot;</span>, <span class="st">&quot;sex&quot;</span>, <span class="st">&quot;mdquality.s&quot;</span>)] <span class="sc">%&gt;%</span> </span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">table</span>(<span class="at">useNA =</span> <span class="st">&quot;ifany&quot;</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">freqlist</span>(<span class="at">groupBy =</span> <span class="fu">c</span>(<span class="st">&quot;arm&quot;</span>, <span class="st">&quot;sex&quot;</span>)) <span class="sc">%&gt;%</span> </span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">write2word</span>(</span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a>    <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.freqlist.doc&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>,</span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">single =</span> <span class="cn">FALSE</span>,         <span class="co"># passed to summary.freqlist</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a>    <span class="at">title =</span> <span class="st">&quot;My cool title&quot;</span> <span class="co"># passed to summary.freqlist</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a>  )</span></code></pre></div>
</div>
<div id="comparedf" class="section level2">
<h2><code>comparedf</code></h2>
<p>For <code>comparedf</code> objects, the output function in <code>write2()</code> is <code>summary()</code>. For <code>summary.comparedf</code> objects, the output function is <code>print()</code>.</p>
</div>
</div>
<div id="examples-using-other-objects" class="section level1">
<h1>Examples Using Other Objects</h1>
<div id="knitrkable" class="section level2">
<h2><code>knitr::kable()</code></h2>
<p>For objects resulting from a call to <code>kable()</code>, the output function in <code>write2()</code> is <code>print()</code>. There aren’t any arguments to the <code>print.knitr_kable()</code> function.</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>mockstudy <span class="sc">%&gt;%</span> </span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">head</span>() <span class="sc">%&gt;%</span> </span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>  knitr<span class="sc">::</span><span class="fu">kable</span>() <span class="sc">%&gt;%</span> </span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">write2html</span>(<span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.kable.html&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
</div>
<div id="xtablextable" class="section level2">
<h2><code>xtable::xtable()</code></h2>
<p>For <code>xtable</code> objects, the output function in <code>write2()</code> is <code>print()</code>. For available arguments, see the help pages for <code>print.xtable()</code>.</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>mockstudy <span class="sc">%&gt;%</span> </span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">head</span>() <span class="sc">%&gt;%</span> </span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a>  xtable<span class="sc">::</span><span class="fu">xtable</span>(<span class="at">caption =</span> <span class="st">&quot;My xtable&quot;</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">write2pdf</span>(</span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a>    <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.xtable.pdf&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>,</span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">comment =</span> <span class="cn">FALSE</span>, <span class="co"># passed to print.xtable to turn off the default message about xtable version</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a>    <span class="at">include.rownames =</span> <span class="cn">FALSE</span>, <span class="co"># passed to print.xtable</span></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a>    <span class="at">caption.placement =</span> <span class="st">&quot;top&quot;</span> <span class="co"># passed to print.xtable</span></span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a>  )</span></code></pre></div>
<p>To make an HTML document, use the <code>print.xtable()</code> option <code>type = &quot;html&quot;</code>.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>mockstudy <span class="sc">%&gt;%</span> </span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">head</span>() <span class="sc">%&gt;%</span> </span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a>  xtable<span class="sc">::</span><span class="fu">xtable</span>(<span class="at">caption =</span> <span class="st">&quot;My xtable&quot;</span>) <span class="sc">%&gt;%</span> </span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">write2html</span>(</span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a>    <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.xtable.html&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>,</span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a>    <span class="at">type =</span> <span class="st">&quot;html&quot;</span>,            <span class="co"># passed to print.xtable</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a>    <span class="at">comment =</span> <span class="cn">FALSE</span>, <span class="co"># passed to print.xtable to turn off the default message about xtable version</span></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a>    <span class="at">include.rownames =</span> <span class="cn">FALSE</span>, <span class="co"># passed to print.xtable</span></span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a>    <span class="at">caption.placement =</span> <span class="st">&quot;top&quot;</span> <span class="co"># passed to print.xtable</span></span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true" tabindex="-1"></a>  )</span></code></pre></div>
<p>User beware! <code>xtable()</code> is not compatible with <code>write2word()</code>.</p>
</div>
<div id="panderpander_return" class="section level2">
<h2><code>pander::pander_return()</code></h2>
<p>Pander is a little bit more tricky. Since <code>pander::pander()</code> doesn’t return an object, the useR should instead use <code>pander::pander_return()</code>. For this (and for all character vectors), the the output function in <code>write2()</code> is <code>cat(sep = &#39;\n&#39;)</code>.</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">write2word</span>(pander<span class="sc">::</span><span class="fu">pander_return</span>(<span class="fu">head</span>(mockstudy)), <span class="at">file =</span> <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.pander.doc&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
</div>
</div>
<div id="output-multiple-tables-to-one-document" class="section level1">
<h1>Output Multiple Tables to One Document</h1>
<p>To output multiple tables into a document, simply make a list of them and call the same function as before.</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>mylist <span class="ot">&lt;-</span> <span class="fu">list</span>(</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tableby</span>(sex <span class="sc">~</span> age, <span class="at">data =</span> mockstudy),</span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">freqlist</span>(<span class="fu">table</span>(mockstudy[, <span class="fu">c</span>(<span class="st">&quot;sex&quot;</span>, <span class="st">&quot;arm&quot;</span>)])),</span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a>  knitr<span class="sc">::</span><span class="fu">kable</span>(<span class="fu">head</span>(mockstudy))</span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true" tabindex="-1"></a><span class="fu">write2pdf</span>(mylist, <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.mylist.pdf&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
<p>One neat side-effect of this function is that you can output text and headers, etc. The possibilities are endless!</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>mylist2 <span class="ot">&lt;-</span> <span class="fu">list</span>(</span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;# Header 1&quot;</span>,</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;This is a small paragraph introducing tableby.&quot;</span>,</span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tableby</span>(sex <span class="sc">~</span> age, <span class="at">data =</span> mockstudy),</span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;&lt;hr&gt;&quot;</span>,</span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;# Header 2&quot;</span>,</span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;&lt;font color=&#39;red&#39;&gt;I can change color of my text!&lt;/font&gt;&quot;</span></span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a><span class="fu">write2html</span>(mylist2, <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.mylist2.html&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
<p>In fact, you can even recurse on the lists!</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="fu">write2pdf</span>(<span class="fu">list</span>(mylist2, mylist), <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.mylists.pdf&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
</div>
<div id="output-other-objects-monospaced-as-if-in-a-terminal" class="section level1">
<h1>Output Other Objects Monospaced (as if in a terminal)</h1>
<p>It may be useful at times to write output that would normally be copied from the terminal. The default method for <code>write2()</code> does this automatically. To output the results of <code>summary.lm()</code>, for example:</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="fu">lm</span>(age <span class="sc">~</span> sex, <span class="at">data =</span> mockstudy) <span class="sc">%&gt;%</span> </span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summary</span>() <span class="sc">%&gt;%</span> </span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">write2pdf</span>(<span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.lm.pdf&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
<p>The <code>verbatim()</code> function is another option to explicitly alert <code>write2()</code> to do this. This becomes particularly helpful to overrule existing S3 methods.</p>
<p>For example, suppose you wanted to just print a tableby object (as if it were to print in the terminal):</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>tab4 <span class="ot">&lt;-</span> <span class="fu">tableby</span>(arm <span class="sc">~</span> sex <span class="sc">+</span> age, <span class="at">data=</span>mockstudy)</span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a><span class="fu">write2html</span>(<span class="fu">verbatim</span>(tab4), <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.print.tableby.html&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
<p>Or suppose you wanted to print a character vector (as if it were to print in the terminal):</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>chr <span class="ot">&lt;-</span> <span class="fu">paste0</span>(<span class="st">&quot;MyVector&quot;</span>, <span class="dv">1</span><span class="sc">:</span><span class="dv">10</span>)</span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a><span class="fu">write2pdf</span>(<span class="fu">verbatim</span>(chr), <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.character.pdf&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
<p>Note that you can combine multiple objects in one call:</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="fu">write2pdf</span>(<span class="fu">verbatim</span>(tab4, chr), <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.verbatim.pdf&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
</div>
<div id="add-a-yaml-header-to-the-output" class="section level1">
<h1>Add a YAML Header to the Output</h1>
<p>You can add a YAML header to <code>write2()</code> output using the <code>yaml()</code> function.</p>
<div class="sourceCode" id="cb16"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a>mylist3 <span class="ot">&lt;-</span> <span class="fu">list</span>(</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">yaml</span>(<span class="at">title =</span> <span class="st">&quot;Test YAML Title&quot;</span>, <span class="at">author =</span> <span class="st">&quot;My cool author name&quot;</span>),</span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;# Header 1&quot;</span>,</span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;This is a small paragraph introducing tableby.&quot;</span>,</span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tableby</span>(sex <span class="sc">~</span> age, <span class="at">data =</span> mockstudy)</span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true" tabindex="-1"></a><span class="fu">write2html</span>(mylist3, <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.yaml.html&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
<p>In fact, all detected YAML pieces will be moved as the first output, so that the above code chunk gives the same output as this one:</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>mylist4 <span class="ot">&lt;-</span> <span class="fu">list</span>(</span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;# Header 1&quot;</span>,</span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;This is a small paragraph introducing tableby.&quot;</span>,</span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">yaml</span>(<span class="at">title =</span> <span class="st">&quot;Test YAML Title&quot;</span>),</span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tableby</span>(sex <span class="sc">~</span> age, <span class="at">data =</span> mockstudy),</span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true" tabindex="-1"></a>  <span class="fu">yaml</span>(<span class="at">author =</span> <span class="st">&quot;My cool author name&quot;</span>)</span>
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb17-8"><a href="#cb17-8" aria-hidden="true" tabindex="-1"></a><span class="fu">write2html</span>(mylist4, <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.yaml2.html&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
</div>
<div id="add-a-code-chunk-to-the-output" class="section level1">
<h1>Add a Code Chunk to the Output</h1>
<p>It is now possible to add code chunks to the output <code>.Rmd</code>:</p>
<div class="sourceCode" id="cb18"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>mylist5 <span class="ot">&lt;-</span> <span class="fu">list</span>(</span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;# What is 1 + 2?&quot;</span>,</span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">code.chunk</span>(a <span class="ot">&lt;-</span> <span class="dv">1</span>, b <span class="ot">&lt;-</span> <span class="dv">2</span>),</span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">code.chunk</span>(a <span class="sc">+</span> b, <span class="at">chunk.opts =</span> <span class="st">&quot;r echo=FALSE, eval=TRUE&quot;</span>)</span>
<span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a><span class="fu">write2html</span>(mylist5, <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.code.chunk.html&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
<p>This allow flexibility to create objects on-the-fly, to read in saved objects to the temporary <code>.Rmd</code>, etc. The possibilities are endless!</p>
</div>
<div id="faqs" class="section level1">
<h1>FAQs</h1>
<div id="how-do-i-suppress-the-note-about-my-document-getting-rendered" class="section level2">
<h2>How do I suppress the note about my document getting rendered?</h2>
<p>This is easily accomplished by using the argument <code>quiet = TRUE</code> (passed to the <code>rmarkdown::render()</code> function).</p>
<div class="sourceCode" id="cb19"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="fu">write2html</span>(</span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a>  knitr<span class="sc">::</span><span class="fu">kable</span>(<span class="fu">head</span>(mockstudy)), <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.kable.quiet.html&quot;</span>),</span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a>  <span class="at">quiet =</span> <span class="cn">TRUE</span> <span class="co"># passed to rmarkdown::render</span></span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div>
</div>
<div id="how-do-i-look-at-the-temporary-.rmd-file" class="section level2">
<h2>How do I look at the temporary <code>.Rmd</code> file?</h2>
<p>This is easily accomplished by using the option <code>keep.rmd = TRUE</code>.</p>
<div class="sourceCode" id="cb20"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="fu">write2html</span>(</span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a>  knitr<span class="sc">::</span><span class="fu">kable</span>(<span class="fu">head</span>(mockstudy)), <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.kable.keep.rmd.html&quot;</span>),</span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a>  <span class="at">quiet =</span> <span class="cn">TRUE</span>, <span class="co"># passed to rmarkdown::render</span></span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a>  <span class="at">keep.rmd =</span> <span class="cn">TRUE</span></span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div>
</div>
<div id="how-do-i-prevent-my-document-from-being-rendered" class="section level2">
<h2>How do I prevent my document from being rendered?</h2>
<p>This is easily accomplished by using the option <code>render. = FALSE</code>. Note that this will then default to <code>keep.rmd = TRUE</code>.</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="fu">write2html</span>(</span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a>  knitr<span class="sc">::</span><span class="fu">kable</span>(<span class="fu">head</span>(mockstudy)), <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.kable.dont.render.html&quot;</span>),</span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a>  <span class="at">render. =</span> <span class="cn">FALSE</span></span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div>
</div>
<div id="how-do-i-output-headers-raw-htmllatex-paragraphs-etc." class="section level2">
<h2>How do I output headers, raw HTML/LaTeX, paragraphs, etc.?</h2>
<p>One can simply abuse the list S3 method for <code>write2()</code>!</p>
<div class="sourceCode" id="cb22"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>mylist2 <span class="ot">&lt;-</span> <span class="fu">list</span>(</span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;# Header 1&quot;</span>,</span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;This is a small paragraph introducing tableby.&quot;</span>,</span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tableby</span>(sex <span class="sc">~</span> age, <span class="at">data =</span> mockstudy),</span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;&lt;hr&gt;&quot;</span>,</span>
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;# Header 2&quot;</span>,</span>
<span id="cb22-7"><a href="#cb22-7" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;&lt;font color=&#39;red&#39;&gt;I can change color of my text!&lt;/font&gt;&quot;</span></span>
<span id="cb22-8"><a href="#cb22-8" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb22-9"><a href="#cb22-9" aria-hidden="true" tabindex="-1"></a><span class="fu">write2html</span>(mylist2, <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.mylist2.html&quot;</span>), <span class="at">quiet =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
</div>
<div id="how-do-i-tweak-the-default-format-from-write2word-write2html-or-write2pdf" class="section level2">
<h2>How do I tweak the default format from <code>write2word()</code>, <code>write2html()</code>, or <code>write2pdf()</code>?</h2>
<p>You can pass arguments to the format functions used behind the scenes.</p>
<div class="sourceCode" id="cb23"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="fu">write2html</span>(</span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a>  knitr<span class="sc">::</span><span class="fu">kable</span>(<span class="fu">head</span>(mockstudy)), <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.kable.theme.html&quot;</span>),</span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a>  <span class="at">quiet =</span> <span class="cn">TRUE</span>,  <span class="co"># passed to rmarkdown::render</span></span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a>  <span class="at">theme =</span> <span class="st">&quot;yeti&quot;</span> <span class="co"># passed to rmarkdown::html_document</span></span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div>
<p>See the help pages for <code>rmarkdown::word_document()</code>, <code>rmarkdown::html_document()</code>, and <code>rmarkdown::pdf_document()</code>.</p>
</div>
<div id="how-do-i-output-to-a-file-format-other-than-word-html-and-pdf" class="section level2">
<h2>How do I output to a file format other than word, HTML, and PDF?</h2>
<p>This can be done using the generic <code>write2()</code> function. The last argument in the function can be another format specification. For details on the acceptable inputs, see the help page for <code>write2()</code>.</p>
<div class="sourceCode" id="cb24"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a><span class="fu">write2</span>(</span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a>  knitr<span class="sc">::</span><span class="fu">kable</span>(<span class="fu">head</span>(mockstudy[, <span class="dv">1</span><span class="sc">:</span><span class="dv">4</span>])), <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.kable.rtf&quot;</span>),</span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a>  <span class="at">quiet =</span> <span class="cn">TRUE</span>,  <span class="co"># passed to rmarkdown::render</span></span>
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a>  <span class="at">output_format =</span> rmarkdown<span class="sc">::</span>rtf_document</span>
<span id="cb24-5"><a href="#cb24-5" aria-hidden="true" tabindex="-1"></a>)</span></code></pre></div>
</div>
<div id="how-do-i-avoid-prefixes-on-my-table-captions-in-pdf" class="section level2">
<h2>How do I avoid prefixes on my table captions in PDF?</h2>
<p>You can do this pretty easily with the <code>yaml()</code> function:</p>
<div class="sourceCode" id="cb25"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a>mylist5 <span class="ot">&lt;-</span> <span class="fu">list</span>(</span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">yaml</span>(<span class="st">&quot;header-includes&quot;</span> <span class="ot">=</span> <span class="fu">list</span>(<span class="st">&quot;</span><span class="sc">\\</span><span class="st">usepackage[labelformat=empty]{caption}&quot;</span>)),</span>
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;# Header 1&quot;</span>,</span>
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a>  <span class="st">&quot;This is a small paragraph introducing tableby.&quot;</span>,</span>
<span id="cb25-5"><a href="#cb25-5" aria-hidden="true" tabindex="-1"></a>  <span class="fu">tableby</span>(sex <span class="sc">~</span> age, <span class="at">data =</span> mockstudy)</span>
<span id="cb25-6"><a href="#cb25-6" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb25-7"><a href="#cb25-7" aria-hidden="true" tabindex="-1"></a><span class="fu">write2pdf</span>(mylist5, <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.noprefixes.pdf&quot;</span>), <span class="at">title =</span> <span class="st">&quot;My tableby&quot;</span>)</span></code></pre></div>
</div>
<div id="how-do-i-output-multiple-tables-with-different-titles" class="section level2">
<h2>How do I output multiple tables with different titles?</h2>
<p>There are now <code>write2()</code> methods for the summary objects of <code>arsenal</code> functions. This allows you to specify a title for each table:</p>
<div class="sourceCode" id="cb26"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a>mylist6 <span class="ot">&lt;-</span> <span class="fu">list</span>(</span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summary</span>(<span class="fu">tableby</span>(sex <span class="sc">~</span> age, <span class="at">data =</span> mockstudy), <span class="at">title =</span> <span class="st">&quot;A Title for tableby&quot;</span>),</span>
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summary</span>(<span class="fu">modelsum</span>(age <span class="sc">~</span> sex, <span class="at">data =</span> mockstudy), <span class="at">title =</span> <span class="st">&quot;A Title for modelsum&quot;</span>),</span>
<span id="cb26-4"><a href="#cb26-4" aria-hidden="true" tabindex="-1"></a>  <span class="fu">summary</span>(<span class="fu">freqlist</span>(<span class="sc">~</span> sex, <span class="at">data =</span> mockstudy), <span class="at">title =</span> <span class="st">&quot;A Title for freqlist&quot;</span>)</span>
<span id="cb26-5"><a href="#cb26-5" aria-hidden="true" tabindex="-1"></a>)</span>
<span id="cb26-6"><a href="#cb26-6" aria-hidden="true" tabindex="-1"></a><span class="fu">write2pdf</span>(mylist6, <span class="fu">paste0</span>(tmpdir, <span class="st">&quot;/test.multiple.titles.pdf&quot;</span>))</span></code></pre></div>
</div>
<div id="why-is-write2-not-working-in-r-markdownr-studio" class="section level2">
<h2>Why is <code>write2()</code> not working in R Markdown/R Studio?</h2>
<p>It’s possible that a global option in R Studio is preventing the tables from rendering. Consider turning off (i.e., unchecking) the option Tools &gt; Global Options &gt; R Markdown &gt; Show output inline for all R Markdown documents.</p>
</div>
</div>



<!-- code folding -->


<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src  = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>

</body>
</html>