Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

iteratelist

Create an iteration list from a R object


Description

In some case it is useful to iterate over a named list or vector iteratelist will create a new unnamed list with name value members: each item will be a list where 'name' is the corresponding name and 'value' is the original value in list x.

Usage

iteratelist(x, name = "name", value = "value")

Arguments

x

list or other object that will be coerced to list

name

character name for resulting name member.

value

character name for resulting value member.

Value

unnamed list with name value lists

Examples

# create an iteration list from a named vector
x <- c(a=1, b=2)
iteratelist(x)

# iterate over the members of a list
x <- list(name="John", age="30", gender="male")
iteratelist(x, name="variable") 

# iterate over an unnamed vector
values <- c(1,2,3,4)

template <- 
'{{#values}}
* Value: {{.}}
{{/values}}'

whisker.render(template)

#or 

values <- iteratelist(values, value="count")

template <- 
'{{#values}}
* Value: {{count}}
{{/values}}'

whisker.render(template)

whisker

{{mustache}} for R, Logicless Templating

v0.4
GPL-3
Authors
Edwin de Jonge
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.