Skip to content

Commit 8094623

Browse files
committed
Run air format . to update formatting
1 parent e794ac8 commit 8094623

File tree

4 files changed

+92
-36
lines changed

4 files changed

+92
-36
lines changed

src/resources/rmd/execute.R

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ execute <- function(
1919
markdown
2020
) {
2121
# calculate knit_root_dir (before we setwd below)
22-
knit_root_dir <- if (!is.null(cwd)) tools::file_path_as_absolute(cwd) else
22+
knit_root_dir <- if (!is.null(cwd)) {
23+
tools::file_path_as_absolute(cwd)
24+
} else {
2325
NULL
26+
}
2427

2528
# change to input dir and make input relative (matches
2629
# behavior/expectations of rmarkdown::render code)
@@ -210,8 +213,11 @@ execute <- function(
210213
# include supporting files
211214
supporting <- if (
212215
!is.null(intermediates_dir) && file_test("-d", intermediates_dir)
213-
)
214-
rmarkdown:::abs_path(intermediates_dir) else character()
216+
) {
217+
rmarkdown:::abs_path(intermediates_dir)
218+
} else {
219+
character()
220+
}
215221

216222
# ammend knit_meta with paged table if df_print == "paged"
217223
if (df_print == "paged") {
@@ -287,7 +293,9 @@ knitr_options <- function(format, resourceDir, handledLanguages) {
287293

288294
# opt_knit for compatibility w/ rmarkdown::render
289295
to <- format$pandoc$to
290-
if (identical(to, "pdf")) to <- "latex"
296+
if (identical(to, "pdf")) {
297+
to <- "latex"
298+
}
291299
opts_knit <- list(
292300
quarto.version = 1,
293301
rmarkdown.pandoc.from = format$pandoc$from,
@@ -397,7 +405,9 @@ knitr_options_with_cache <- function(input, format, opts) {
397405
knitr_cache_dir <- function(input, format) {
398406
pandoc_to <- format$pandoc$to
399407
base_pandoc_to <- gsub('[-+].*', '', pandoc_to)
400-
if (base_pandoc_to == 'html4') base_pandoc_to <- 'html'
408+
if (base_pandoc_to == 'html4') {
409+
base_pandoc_to <- 'html'
410+
}
401411
cache_dir <- rmarkdown:::knitr_cache_dir(input, base_pandoc_to)
402412
cache_dir <- gsub("/$", "", cache_dir)
403413
cache_dir
@@ -669,8 +679,9 @@ is_dashboard_output <- function(format) {
669679

670680
# apply patches to output as required
671681
apply_patches <- function(format, includes) {
672-
if (format$pandoc$to %in% c("slidy", "revealjs"))
682+
if (format$pandoc$to %in% c("slidy", "revealjs")) {
673683
includes <- apply_slides_patch(includes)
684+
}
674685
includes
675686
}
676687

@@ -771,12 +782,15 @@ has_crop_tools <- function(warn = TRUE) {
771782
ghostscript = unname(tools::find_gs_cmd())
772783
)
773784
missing <- tools[tools == ""]
774-
if (length(missing) == 0) return(TRUE)
785+
if (length(missing) == 0) {
786+
return(TRUE)
787+
}
775788
x <- paste0(names(missing), collapse = ", ")
776-
if (warn)
789+
if (warn) {
777790
warning(
778791
sprintf("\nTool(s) not installed or not in PATH: %s", x),
779792
"\n-> As a result, figure cropping will be disabled."
780793
)
794+
}
781795
FALSE
782796
}

src/resources/rmd/hooks.R

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ knitr_hooks <- function(format, resourceDir, handledLanguages) {
159159
opts_hooks[[option]] <<- function(options) {
160160
if (identical(options[[option]], FALSE)) {
161161
options[[option]] <- TRUE
162-
for (hide in hidden) options[[paste0(hide, ".hidden")]] <- TRUE
162+
for (hide in hidden) {
163+
options[[paste0(hide, ".hidden")]] <- TRUE
164+
}
163165
}
164166
options
165167
}
@@ -191,8 +193,9 @@ knitr_hooks <- function(format, resourceDir, handledLanguages) {
191193
# prefix for classes
192194
classes <- c("cell-output", paste0("cell-output-", classes))
193195
# add .hidden class if keep-hidden hook injected an option
194-
if (isTRUE(options[[paste0(type, ".hidden")]]))
196+
if (isTRUE(options[[paste0(type, ".hidden")]])) {
195197
classes <- c(classes, "hidden")
198+
}
196199
output_div(x, NULL, classes)
197200
}
198201
})
@@ -390,26 +393,32 @@ knitr_hooks <- function(format, resourceDir, handledLanguages) {
390393
forwardAttr,
391394
sprintf("%s='%s'", unknown_opts, unknown_values)
392395
)
393-
if (length(forwardAttr) > 0)
394-
forwardAttr <- paste0(" ", paste(forwardAttr, collapse = " ")) else
396+
if (length(forwardAttr) > 0) {
397+
forwardAttr <- paste0(" ", paste(forwardAttr, collapse = " "))
398+
} else {
395399
forwardAttr <- ""
400+
}
396401

397402
# handle classes
398403
classes <- c("cell", options[["classes"]])
399-
if (is.character(options[["panel"]]))
404+
if (is.character(options[["panel"]])) {
400405
classes <- c(classes, paste0("panel-", options[["panel"]]))
401-
if (is.character(options[["column"]]))
406+
}
407+
if (is.character(options[["column"]])) {
402408
classes <- c(classes, paste0("column-", options[["column"]]))
409+
}
403410
if (is.character(options[["fig-column"]])) {
404411
classes <- c(classes, paste0("fig-column-", options[["fig-column"]]))
405412
} else if (is.character(options[["fig.column"]])) {
406413
# knitr < 1.44 compatibility where fig- -> fig.
407414
classes <- c(classes, paste0("fig-column-", options[["fig.column"]]))
408415
}
409-
if (is.character(options[["tbl-column"]]))
416+
if (is.character(options[["tbl-column"]])) {
410417
classes <- c(classes, paste0("tbl-column-", options[["tbl-column"]]))
411-
if (is.character(options[["cap-location"]]))
418+
}
419+
if (is.character(options[["cap-location"]])) {
412420
classes <- c(classes, paste0("caption-", options[["cap-location"]]))
421+
}
413422
if (is.character(options[["fig-cap-location"]])) {
414423
classes <- c(
415424
classes,
@@ -422,11 +431,12 @@ knitr_hooks <- function(format, resourceDir, handledLanguages) {
422431
paste0("fig-cap-location-", options[["fig.cap-location"]])
423432
)
424433
}
425-
if (is.character(options[["tbl-cap-location"]]))
434+
if (is.character(options[["tbl-cap-location"]])) {
426435
classes <- c(
427436
classes,
428437
paste0("tbl-cap-location-", options[["tbl-cap-location"]])
429438
)
439+
}
430440

431441
if (isTRUE(options[["include.hidden"]])) {
432442
classes <- c(classes, "hidden")
@@ -498,11 +508,11 @@ knitr_hooks <- function(format, resourceDir, handledLanguages) {
498508
attr <- paste(attr, paste0('lst-cap="', options[["lst-cap"]], '"'))
499509
}
500510
}
501-
if (identical(options[["code-overflow"]], "wrap"))
502-
class <- paste(class, "code-overflow-wrap") else if (
503-
identical(options[["code-overflow"]], "scroll")
504-
)
511+
if (identical(options[["code-overflow"]], "wrap")) {
512+
class <- paste(class, "code-overflow-wrap")
513+
} else if (identical(options[["code-overflow"]], "scroll")) {
505514
class <- paste(class, "code-overflow-scroll")
515+
}
506516
fold <- options[["code-fold"]]
507517
if (!is.null(fold)) {
508518
attr <- paste(
@@ -615,7 +625,9 @@ knitr_plot_hook <- function(format) {
615625

616626
# classes
617627
classes <- paste0("cell-output-display")
618-
if (isTRUE(options[["plot.hidden"]])) classes <- c(classes, "hidden")
628+
if (isTRUE(options[["plot.hidden"]])) {
629+
classes <- c(classes, "hidden")
630+
}
619631

620632
# label
621633
placeholder <- output_label_placeholder(options)
@@ -746,7 +758,9 @@ knitr_plot_hook <- function(format) {
746758
}
747759

748760
# result = "asis" specific
749-
if (identical(options[["results"]], "asis")) return(md)
761+
if (identical(options[["results"]], "asis")) {
762+
return(md)
763+
}
750764

751765
# enclose in output div
752766
output_div(md, NULL, classes)
@@ -1063,8 +1077,13 @@ figure_cap <- function(options) {
10631077
if (is.null(output_label) || is_figure_label(output_label)) {
10641078
fig.cap <- options[["fig.cap"]]
10651079
fig.subcap <- options[["fig.subcap"]]
1066-
if (length(fig.subcap) != 0) fig.subcap else if (length(fig.cap) != 0)
1067-
fig.cap else ""
1080+
if (length(fig.subcap) != 0) {
1081+
fig.subcap
1082+
} else if (length(fig.cap) != 0) {
1083+
fig.cap
1084+
} else {
1085+
""
1086+
}
10681087
} else {
10691088
""
10701089
}
@@ -1151,8 +1170,12 @@ latex_animation <- function(x, options) {
11511170

11521171
ow = options$out.width
11531172
# maxwidth does not work with animations
1154-
if (identical(ow, '\\maxwidth')) ow = NULL
1155-
if (is.numeric(ow)) ow = paste0(ow, 'px')
1173+
if (identical(ow, '\\maxwidth')) {
1174+
ow = NULL
1175+
}
1176+
if (is.numeric(ow)) {
1177+
ow = paste0(ow, 'px')
1178+
}
11561179
size = paste(
11571180
c(
11581181
sprintf('width=%s', ow),
@@ -1165,7 +1188,9 @@ latex_animation <- function(x, options) {
11651188
aniopts = options$aniopts
11661189
aniopts = if (is.na(aniopts)) NULL else gsub(';', ',', aniopts)
11671190
size = paste(c(size, sprintf('%s', aniopts)), collapse = ',')
1168-
if (nzchar(size)) size = sprintf('[%s]', size)
1191+
if (nzchar(size)) {
1192+
size = sprintf('[%s]', size)
1193+
}
11691194
sprintf(
11701195
'\\animategraphics%s{%s}{%s}{%s}{%s}',
11711196
size,

src/resources/rmd/patch.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ wrap_asis_output <- function(options, x) {
111111
}
112112
classes <- paste0("cell-output-display")
113113
attrs <- NULL
114-
if (isTRUE(options[["output.hidden"]])) classes <- paste0(classes, " .hidden")
114+
if (isTRUE(options[["output.hidden"]])) {
115+
classes <- paste0(classes, " .hidden")
116+
}
115117

116118
if (identical(options[["html-table-processing"]], "none")) {
117119
attrs <- paste(attrs, "html-table-processing=none")
@@ -130,7 +132,9 @@ wrap_asis_output <- function(options, x) {
130132
}
131133

132134
# If asis output, don't include the output div
133-
if (identical(options[["results"]], "asis")) return(x)
135+
if (identical(options[["results"]], "asis")) {
136+
return(x)
137+
}
134138

135139
output_div(x, output_label_placeholder(options), classes, attrs)
136140
}

src/resources/rmd/rmd.R

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@
3434
knit_meta <- lapply(data, jsonlite::unserializeJSON)
3535

3636
# determine files_dir
37-
files_dir <- if (!is.null(libDir)) libDir else
37+
files_dir <- if (!is.null(libDir)) {
38+
libDir
39+
} else {
3840
rmarkdown:::knitr_files_dir(output)
41+
}
3942

4043
# yield pandoc format
4144
list(
@@ -60,7 +63,9 @@
6063

6164
# bail if we don't have any perserved chunks and aren't doing code linking
6265
code_link <- isHTML && isTRUE(format$render$`code-link`)
63-
if (length(preserved_chunks) == 0 && code_link == FALSE) return()
66+
if (length(preserved_chunks) == 0 && code_link == FALSE) {
67+
return()
68+
}
6469

6570
# change to input dir and make input relative
6671
oldwd <- setwd(dirname(rmarkdown:::abs_path(input)))
@@ -191,8 +196,12 @@
191196

192197
run <- function(input, port, host) {
193198
shiny_args <- list()
194-
if (!is.null(port)) shiny_args$port <- port
195-
if (!is.null(host)) shiny_args$host <- host
199+
if (!is.null(port)) {
200+
shiny_args$port <- port
201+
}
202+
if (!is.null(host)) {
203+
shiny_args$host <- host
204+
}
196205

197206
# we already ran quarto render before the call to run
198207
Sys.setenv(RMARKDOWN_RUN_PRERENDER = "0")
@@ -226,7 +235,9 @@
226235
# print execute-debug message ("spin" and "run" don't pass format option)
227236
debug <- (!request$action %in% c("spin", "run")) &&
228237
isTRUE(params$format$execute[["debug"]])
229-
if (debug) message("[knitr engine]: ", request$action)
238+
if (debug) {
239+
message("[knitr engine]: ", request$action)
240+
}
230241

231242
# dispatch request
232243
if (request$action == "spin") {
@@ -267,7 +278,9 @@
267278
}
268279

269280
# write results
270-
if (debug) message("[knitr engine]: writing results")
281+
if (debug) {
282+
message("[knitr engine]: writing results")
283+
}
271284
resultJson <- jsonlite::toJSON(auto_unbox = TRUE, result)
272285
xfun:::write_utf8(paste(resultJson, collapse = "\n"), request[["results"]])
273286
if (debug) message("[knitr engine]: exiting")

0 commit comments

Comments
 (0)