render_template: Compile a R/markdown Template

Description Usage Arguments Value

Description

Calls "knit()" on the template given, directing output to the given output name, and doing this in a way that doesn't cause collisions between parallel instances of this script.

Usage

1
2
3
4
5
6
render_template(template, output = gsub("[.](Rmd|md)$", ".html", template),
  html = grepl("html$", output), md.file = gsub("[.](html|md)$", ".md",
  output), resource.dir = system.file(package = "templater"),
  macros = "macros.tex", opts.knit = NULL, change.rootdir = FALSE,
  mathjax.loc = "/usr/share/javascript/mathjax/MathJax.js", verbose = TRUE,
  clean = FALSE, width = "940px", pandoc.exec = "pandoc", ...)

Arguments

template

Name of .Rmd file.

output

Name of output .md or .html file.

html

Run pandoc to compile html from the .md?

md.file

Name of the .md output file.

resource.dir

Directory that files referenced in pandoc options are in.

macros

Name of a file with LaTeX macros.

opts.knit

List of additional options for knitr::opts_knit$set().

change.rootdir

Whether to evalute the template in the output directory (rather than the template directory).

mathjax.loc

Location to look for a local copy of MathJax (harmless if not present).

verbose

Whether to print commands sufficient to recreate what is done.

clean

Whether to delete intermediate files (the .md file, if the output is html).

width

The width of the container (in valid html code).

pandoc.exec

Name of the pandoc executable.

...

Additional parameters passed to knitr::knit().

Value

The name of the output file. Note that by default, both knitr and pandoc look for figures relative to the *current directory*, not the directory that the markdown file lives in. This makes subsequent parsing of the markdown file difficult. To avoid this, here we switch to the directory of the markdown file before running either.

If the name of the output is 'outdir/out.html', then the 'cache' and 'figure' directories for knitr will be 'outdir/cache/out/' and 'outdir/figure/out', respectively. This ensures that separate output files have distinct caches and figures.

This executes in the output directory (precisely, the directory where md.file lives), which is not necessarily in the same directory as the template.

The html document produced will use the copy of MathJax at mathjax.loc if it is not NULL and that file is present, but will fall back on the CDN https://cdn.mathjax.org/mathjax/latest/MathJax.js if it is not.

If you want the code in the .Rmd file to be evaluated in the current environment, as is the default if you call knit("myfile.Rmd"), then pass the option envir=environment() (or, envir=globalenv() if you want the global environment).


petrelharp/templater documentation built on May 25, 2019, 2:54 a.m.