Learn R Programming

knitr (version 1.48)

knit_expand: 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 = read_utf8(file), delim = c("{{", "}}"))

Value

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

Arguments

file

The template file.

...

A list of variables to be used for the code in the template; note that the variables will be searched for in the parent frame as well.

text

Character vector of lines of code. An alternative way to specify the template code directly. If text is provided, file will be ignored.

delim

A pair of opening and closing delimiters for the templating tags.

References

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

Examples

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

Run the code above in your browser using DataLab