|
34 | 34 | knit_meta <- lapply(data, jsonlite::unserializeJSON) |
35 | 35 |
|
36 | 36 | # determine files_dir |
37 | | - files_dir <- if (!is.null(libDir)) libDir else |
| 37 | + files_dir <- if (!is.null(libDir)) { |
| 38 | + libDir |
| 39 | + } else { |
38 | 40 | rmarkdown:::knitr_files_dir(output) |
| 41 | + } |
39 | 42 |
|
40 | 43 | # yield pandoc format |
41 | 44 | list( |
|
60 | 63 |
|
61 | 64 | # bail if we don't have any perserved chunks and aren't doing code linking |
62 | 65 | 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 | + } |
64 | 69 |
|
65 | 70 | # change to input dir and make input relative |
66 | 71 | oldwd <- setwd(dirname(rmarkdown:::abs_path(input))) |
|
97 | 102 | # within a code chunk |
98 | 103 | for (x in seq_along(chunkStarts)) { |
99 | 104 | start <- chunkStarts[x] |
100 | | - end <- chunkEnds[x] |
| 105 | + # Ensure end is greater than start |
| 106 | + end <- start |
| 107 | + for (e in chunkEnds) { |
| 108 | + if (e > start) { |
| 109 | + end <- e |
| 110 | + break |
| 111 | + } |
| 112 | + } |
101 | 113 | for (y in start:end) { |
102 | 114 | if (y > start && y < end) { |
103 | 115 | chunkMap[y] <- TRUE |
|
107 | 119 |
|
108 | 120 | # look for at least one annotations that is in a code chunk |
109 | 121 | for (a in annotations) { |
110 | | - if (chunkMap[a] == TRUE) { |
| 122 | + if (chunkMap[a]) { |
111 | 123 | hasAnnotations <- TRUE |
112 | 124 | break |
113 | 125 | } |
|
191 | 203 |
|
192 | 204 | run <- function(input, port, host) { |
193 | 205 | shiny_args <- list() |
194 | | - if (!is.null(port)) shiny_args$port <- port |
195 | | - if (!is.null(host)) shiny_args$host <- host |
| 206 | + if (!is.null(port)) { |
| 207 | + shiny_args$port <- port |
| 208 | + } |
| 209 | + if (!is.null(host)) { |
| 210 | + shiny_args$host <- host |
| 211 | + } |
196 | 212 |
|
197 | 213 | # we already ran quarto render before the call to run |
198 | 214 | Sys.setenv(RMARKDOWN_RUN_PRERENDER = "0") |
|
226 | 242 | # print execute-debug message ("spin" and "run" don't pass format option) |
227 | 243 | debug <- (!request$action %in% c("spin", "run")) && |
228 | 244 | isTRUE(params$format$execute[["debug"]]) |
229 | | - if (debug) message("[knitr engine]: ", request$action) |
| 245 | + if (debug) { |
| 246 | + message("[knitr engine]: ", request$action) |
| 247 | + } |
230 | 248 |
|
231 | 249 | # dispatch request |
232 | 250 | if (request$action == "spin") { |
|
267 | 285 | } |
268 | 286 |
|
269 | 287 | # write results |
270 | | - if (debug) message("[knitr engine]: writing results") |
| 288 | + if (debug) { |
| 289 | + message("[knitr engine]: writing results") |
| 290 | + } |
271 | 291 | resultJson <- jsonlite::toJSON(auto_unbox = TRUE, result) |
272 | 292 | xfun:::write_utf8(paste(resultJson, collapse = "\n"), request[["results"]]) |
273 | 293 | if (debug) message("[knitr engine]: exiting") |
|
0 commit comments