File: render_one.R

package info (click to toggle)
r-cran-bookdown 0.32%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,664 kB
  • sloc: javascript: 11,322; makefile: 21; sh: 20
file content (26 lines) | stat: -rw-r--r-- 837 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
# compile an Rmd file without running Pandoc; arguments are passed from Rscript;
# the three arguments are 1) the Rmd filename; 2) the render arguments; 3) the
# filename to save the returned value of render(); 4) before_chapter_script; 5)
# after_chapter_script
library(methods)
local({
  args = commandArgs(TRUE)

  bookdown:::source_utf8(args[4])
  out = do.call(
    rmarkdown::render, c(args[1], readRDS(args[2]), list(run_pandoc = FALSE))
  )
  bookdown:::source_utf8(args[5])

  out_expected = xfun::with_ext(args[1], '.md')
  if (out != out_expected) {
    file.rename(out, out_expected)
    attributes(out_expected) = attributes(out)
    out = out_expected
  }
  if (file.exists(args[3])) {
    res = readRDS(args[3])
    res[[args[1]]] = out
    saveRDS(res, args[3])
  } else saveRDS(setNames(list(out), args[1]), args[3])
})