utils: Update and evaluate templates

tmplUpdateR Documentation

Update and evaluate templates

Description

Functions operating on tmpl objects. They can be updated and / or evaluated as an expression.

Usage

tmplUpdate(.t, ...)

## S3 method for class 'tmpl'
tmplUpdate(.t, ...)

## S3 method for class 'function'
tmplUpdate(.t, ...)

tmplEval(.t, ..., .envir = new.env(parent = parent.frame()))

tmplAsFun(.t, ...)

Arguments

.t

(tmpl) and object of class tmpl

...

(name = value | name ~ value) name-value expressions used to update the snippets in x

.envir

(environment) the environment in which the template is evaluated

Details

tmplUpdate will evaluate all snippets in a template. Objects are searched for in the list of arguments supplied as ... and the environment of the template. The results are substituted within the snippets.

tmplEval will evaluate the template in place or in the specified environment after substituting the elements in ....

Examples

tmpl("This is {{ a }} very similar to {{ b }}", a = "actually", b = "sprintf")
tmpl("But I consider it to be ({{ sprintf('%i', a) }}) orthogonal", a = 1.0)
tmpl("and ({{ sprintf('%i', b) }}) with a different scope:", b = 2.0)
tmpl("SELECT {{ var }} FROM {{ table }} WHERE {{ condition }};",
     var = "someVar", table = "someTable", condition = "primaryKey = 1")
template <- tmpl("cat({{ toupper(x) }})")
tmplUpdate(template, x ~ "hi")
tmplEval(template, x ~ "hi")


wahani/templates documentation built on March 16, 2024, 11:30 a.m.