R: A simple macro preprocessor for templating purposes

knit_expand {knitr} | R Documentation

## A simple macro preprocessor for templating purposes

### Description

This function expands a template based on the R expressions in `{{}}` (this tag can be customized by the `delim` argument). These expressions are extracted, evaluated and replaced by their values in the original template.

### Usage

    knit_expand(file, ..., text = readLines(file, warn = FALSE), delim = c("{{", "}}"))

### Arguments

`file` | the template file
`...` | a list of variables to be used for the code in the template; note the variables will be searched in the parent frame as well
`text` | an alternative way to `file` to specify the template code directly (if provided, `file` will be ignored)
`delim` | the (opening and ending) delimiters for the templating tags

### Value

A character vector, with the tags evaluated and replaced by their values.

### References

This function was inspired by the pyexpander and m4 (http://www.gnu.org/software/m4/), thanks to Frank Harrell.

### Examples

    # see the knit_expand vignette
    if (interactive()) browseVignettes(package = "knitr")

[Package knitr version 1.16 Index]