Learn R Programming

templates (version 0.4.0)

tmplUpdate: 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 tmpl tmplUpdate(.t, ...)

# S3 method for 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

Run this code
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")

Run the code above in your browser using DataLab