whisker_mapply: whisker_mapply - repeatedly render a template over multiple...

Description Usage Arguments Value See Also Examples

View source: R/whisker_mapply.R

Description

Have a mixture of changing and unchanging template elements.

Usage

1
whisker_mapply(template, data = parent.frame(), partials = list(), ...)

Arguments

template

character

data

named list or environment with variables that will be used during rendering but do not change in each

partials

See whisker.render

...

named list of object that get substituted

whisker_mapply supports a mapply type interface over whisker_render that allows for vector of template renderings.

The advantage of this approach are several-fold:

  • more reusablity of the template

  • cleaner syntax

  • no need to be changing out data

  • less looping

  • template rendered as a vector

Value

character vector of rendered templates

See Also

whisker_render

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
  
  template <- 'type {{type}}: {{uppercase}},{{lowercase}}'
  whisker_mapply( template, list(type="alphabet"), lowercase=letters[1:3], uppercase=LETTERS[1:3] )
  
  # USED IN LOOP ... 
  #  template is pre-defined at top of code (above) and is not changes, 
  #   nor is it required to modify data. This is handled seemlessly. 
  ## Not run: 
  # for( type in 1:2 ) { 
  #   print( whisker_mapply( template, list(type=type, uppercase="A"), lowercase=letters[1:3] ) )
  # }
  # 
## End(Not run)
     

decisionpatterns/whisker.tools documentation built on July 1, 2020, 4:18 p.m.