-
Notifications
You must be signed in to change notification settings - Fork 8
/
render.R
358 lines (326 loc) · 12.2 KB
/
render.R
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
#' Create an R Markdown Word Document Topic Guide
#'
#' This is a function called in the output of the yaml of the Rmd file to
#' specify using the standard DLM topic guide word document formatting.
#'
#' @param ... Arguments to be passed to `[bookdown::word_document2]`
#'
#' @return A modified `word_document2` with the standard topic guide formatting.
#' @export
#'
#' @examples
#' \dontrun{
#' output: ratlas::topicguide_docx
#' }
topicguide_docx <- function(...) {
template <- find_resource("topicguide_docx", "template.docx")
base <- bookdown::word_document2(reference_docx = template, ...)
# nolint start
base$knitr$opts_chunk$comment <- "#>"
base$knitr$opts_chunk$message <- FALSE
base$knitr$opts_chunk$warning <- FALSE
base$knitr$opts_chunk$error <- FALSE
base$knitr$opts_chunk$echo <- FALSE
base$knitr$opts_chunk$cache <- FALSE
base$knitr$opts_chunk$fig.width <- 7
base$knitr$opts_chunk$fig.asp <- 0.618
base$knitr$opts_chunk$fig.ext <- "png"
base$knitr$opts_chunk$fig.retina <- 3
base$knitr$opts_chunk$fig.path <- "figures/"
base$knitr$opts_chunk$fig.pos <- "H"
# nolint end
base
}
#' Create an R Markdown Word Document Topic Guide
#'
#' This is a function called in the output of the yaml of the Rmd file to
#' specify using the standard DLM topic guide word document formatting.
#'
#' @param ... Arguments to be passed to `[bookdown::word_document2]`
#'
#' @return A modified `word_document2` with the standard topic guide formatting.
#' @export
#'
#' @examples
#' \dontrun{
#' output: ratlas::topicguide_rdocx
#' }
topicguide_rdocx <- function(...) {
template <- find_resource("topicguide_rdocx", "template.docx")
base <- officedown::rdocx_document(base_format = "bookdown::word_document2",
reference_docx = template,
number_sections = FALSE,
page_size = list(
width = 8.5, height = 11,
orient = "portrait"
),
page_margins = list(
top = 1, right = 1, bottom = 1, left = .5
),
plots = list(
align = "left", topcaption = TRUE,
caption = list(
style = "Image Caption",
pre = "Figure ",
sep = ": "
)
),
tables = list(
align = "center",
caption = list(
style = "Table Caption",
pre = "Table ",
sep = ": "
)
),
...)
# nolint start
base$knitr$opts_chunk$comment <- "#>"
base$knitr$opts_chunk$message <- FALSE
base$knitr$opts_chunk$warning <- FALSE
base$knitr$opts_chunk$error <- FALSE
base$knitr$opts_chunk$echo <- FALSE
base$knitr$opts_chunk$cache <- FALSE
base$knitr$opts_chunk$fig.width <- 6.4
base$knitr$opts_chunk$fig.asp <- 0.618
base$knitr$opts_chunk$fig.ext <- "png"
base$knitr$opts_chunk$fig.retina <- 3
base$knitr$opts_chunk$fig.path <- "figures/"
base$knitr$opts_chunk$fig.pos <- "H"
base$knitr$opts_chunk$ft.align <- "left"
base$knitr$opts_chunk$ft.split <- FALSE
# nolint end
base
}
#' Create an R Markdown PDF Topic Guide
#'
#' This is a function called in the output of the yaml of the Rmd file to
#' specify using the standard DLM topic guide document formatting.
#'
#' @param ... Arguments to be passed to `[bookdown::pdf_document2]`
#'
#' @return A modified `pdf_document2` with the standard tech report formatting.
#' @export
#'
#' @examples
#' \dontrun{
#' output: ratlas::topicguide_pdf
#' }
topicguide_pdf <- function(...) {
topic_guide_template <- find_resource("topicguide_pdf", "template.tex")
base <- bookdown::pdf_document2(template = topic_guide_template,
latex_engine = "xelatex",
citation_package = "biblatex",
keep_tex = TRUE, number_sections = FALSE, ...)
# nolint start
base$knitr$opts_chunk$comment <- "#>"
base$knitr$opts_chunk$message <- FALSE
base$knitr$opts_chunk$warning <- FALSE
base$knitr$opts_chunk$error <- FALSE
base$knitr$opts_chunk$echo <- FALSE
base$knitr$opts_chunk$cache <- FALSE
base$knitr$opts_chunk$fig.width <- 7
base$knitr$opts_chunk$fig.asp <- 0.618
base$knitr$opts_chunk$fig.ext <- "pdf"
base$knitr$opts_chunk$fig.align <- "center"
base$knitr$opts_chunk$fig.retina <- 3
base$knitr$opts_chunk$fig.path <- "figures/"
base$knitr$opts_chunk$fig.pos <- "H"
base$knitr$opts_chunk$out.extra <- ""
base$knitr$opts_chunk$out.width <- "100%"
base$knitr$opts_chunk$fig.show <- "hold"
# nolint end
base$knitr$knit_hooks$plot <- hook_tex_plot_rat
base
}
#' Create an R Markdown PDF measr Report
#'
#' This is a function called in the output of the yaml of the Rmd file to
#' specify using the standard measr report document formatting.
#'
#' @param ... Arguments to be passed to `[bookdown::pdf_document2]`
#'
#' @return A modified `pdf_document2` with the standard tech report formatting.
#' @export
#'
#' @examples
#' \dontrun{
#' output: ratlas::measr_pdf
#' }
measr_pdf <- function(...) {
report_template <- find_resource("measr_pdf", "template.tex")
base <- bookdown::pdf_document2(template = report_template,
latex_engine = "xelatex",
citation_package = "biblatex",
keep_tex = TRUE, number_sections = FALSE,
highlight = NULL, ...)
# nolint start
base$knitr$opts_chunk$comment <- "#>"
base$knitr$opts_chunk$message <- FALSE
base$knitr$opts_chunk$warning <- FALSE
base$knitr$opts_chunk$error <- FALSE
base$knitr$opts_chunk$echo <- TRUE
base$knitr$opts_chunk$cache <- FALSE
base$knitr$opts_chunk$fig.width <- 7
base$knitr$opts_chunk$fig.asp <- 0.618
base$knitr$opts_chunk$fig.ext <- "pdf"
base$knitr$opts_chunk$fig.align <- "center"
base$knitr$opts_chunk$fig.retina <- 3
base$knitr$opts_chunk$fig.path <- "figures/"
base$knitr$opts_chunk$fig.pos <- "H"
base$knitr$opts_chunk$out.extra <- ""
base$knitr$opts_chunk$out.width <- "100%"
base$knitr$opts_chunk$fig.show <- "hold"
# nolint end
base$knitr$knit_hooks$plot <- hook_tex_plot_rat
base
}
#' Create an R Markdown PDF Document Tech Report
#'
#' This is a function called in the output of the yaml of the Rmd file to
#' specify using the standard DLM tech report pdf document formatting.
#'
#' @param apa6 Should the old
#' @param ... Arguments to be passed to `[bookdown::pdf_document2]`
#'
#' @return A modified `pdf_document2` with the standard tech report formatting.
#' @export
#'
#' @examples
#' \dontrun{
#' output: ratlas::techreport_pdf
#' }
techreport_pdf <- function(apa6 = FALSE, ...) {
template_name <- ifelse(apa6, "apa6-template.tex", "template.tex")
tech_report_template <- find_resource("techreport", template_name)
base <- bookdown::pdf_document2(template = tech_report_template,
latex_engine = "xelatex",
citation_package = "biblatex",
keep_tex = TRUE, ...)
# nolint start
base$knitr$opts_chunk$comment <- "#>"
base$knitr$opts_chunk$message <- FALSE
base$knitr$opts_chunk$warning <- FALSE
base$knitr$opts_chunk$error <- FALSE
base$knitr$opts_chunk$echo <- FALSE
base$knitr$opts_chunk$cache <- FALSE
base$knitr$opts_chunk$fig.width <- 7
base$knitr$opts_chunk$fig.asp <- 0.618
base$knitr$opts_chunk$fig.ext <- "pdf"
base$knitr$opts_chunk$fig.align <- "center"
base$knitr$opts_chunk$fig.retina <- 3
base$knitr$opts_chunk$fig.path <- "figures/"
base$knitr$opts_chunk$fig.pos <- "H"
base$knitr$opts_chunk$out.extra <- ""
base$knitr$opts_chunk$out.width <- "100%"
base$knitr$opts_chunk$fig.show <- "hold"
# nolint end
if (tolower(apa6) %in% c("true", "yes")) {
base$knitr$knit_hooks$plot <- knitr::hook_plot_tex
} else {
base$knitr$knit_hooks$plot <- hook_tex_plot_rat
}
base
}
#' Create an R Markdown GitBook Tech Report
#'
#' This is a function called in the output of the yaml of the Rmd file to
#' specify using the standard DLM tech report pdf document formatting.
#'
#' @param ... Arguments to be passed to `[bookdown::gitbook]`
#'
#' @return A modified `gitbook` with the standard tech report formatting.
#' @export
#'
#' @examples
#' \dontrun{
#' output: ratlas::techreport_gitbook
#' }
techreport_gitbook <- function(...) {
base <-
bookdown::gitbook(css = "assets/style.css",
split_by = "chapter+number",
split_bib = FALSE,
pandoc_args = "--lua-filter=assets/footnote.lua",
includes = list(in_header = "assets/style.html"),
config = list(
toc = list(
collapse = "section",
scroll_highlight = TRUE,
before = glue::glue("<li>",
"<strong>",
"<a href=\"./\">",
"Dynamic Learning Maps",
"</a>",
"</strong>",
"</li>")
),
download = "pdf",
sharing = "no"
), ...)
# nolint start
base$knitr$opts_chunk$comment <- "#>"
base$knitr$opts_chunk$message <- FALSE
base$knitr$opts_chunk$warning <- FALSE
base$knitr$opts_chunk$error <- FALSE
base$knitr$opts_chunk$echo <- FALSE
base$knitr$opts_chunk$cache <- FALSE
base$knitr$opts_chunk$fig.width <- 7
base$knitr$opts_chunk$fig.asp <- 0.618
base$knitr$opts_chunk$fig.ext <- "png"
base$knitr$opts_chunk$fig.align <- "center"
base$knitr$opts_chunk$fig.retina <- 3
base$knitr$opts_chunk$fig.path <- "figures/"
base$knitr$opts_chunk$fig.pos <- "H"
base$knitr$opts_chunk$out.extra <- ""
base$knitr$opts_chunk$out.width <- "100%"
base$knitr$opts_chunk$fig.show <- "hold"
base$knitr$opts_chunk$fig.topcaption <- TRUE
# nolint end
base$knitr$knit_hooks$plot <- hook_html_plot_rat
base
}
#' Create an HTML Slide Deck with R Markdown
#'
#' This is a function called in the output of the YAML of the Rmd file to
#' specify using the standard DLM tech report pdf document formatting.
#'
#' @param ... Arguments to be passed to `[xaringan::moon_reader]`
#'
#' @return A modified `mood_reader` with ATLAS branding applied.
#' @export
#'
#' @examples
#' \dontrun{
#' output: ratlas::slides_html
#' }
slides_html <- function(...) {
default_nature <- list(ratio = "16:9",
highlightStyle = "github",
highlightLines = TRUE,
countIncrementalSlides = FALSE,
slideNumberFormat = "%current%")
dots_args <- list(...)
dots_name <- names(dots_args)
if ("nature" %in% dots_name) {
final_nature <- utils::modifyList(default_nature, dots_args[["nature"]])
} else {
final_nature <- default_nature
}
base <- xaringan::moon_reader(
css = c("default", "assets/css/atlas.css", "assets/css/atlas-fonts.css"),
lib_dir = "libs", nature = final_nature,
includes = list(in_header = "assets/header.html")
)
# nolint start
base$knitr$opts_chunk$comment <- "#>"
base$knitr$opts_chunk$message <- FALSE
base$knitr$opts_chunk$warning <- FALSE
base$knitr$opts_chunk$error <- FALSE
base$knitr$opts_chunk$echo <- FALSE
base$knitr$opts_chunk$cache <- FALSE
base$knitr$opts_chunk$fig.retina <- 3
base$knitr$opts_chunk$fig.path <- "figures/"
# nolint end
base
}