Generate Characters and Named Lists, Vectors and Data Frames with List Comprehension

Functions to transform patterns with placeholders into characters or into names of lists, vectors, or data frames, based on variable ranges and additional conditions.

gen.list.char(str, ...)

gen.vector.char(str, ...)

gen.named.list(str, expr, ...)

gen.named.vector(str, expr, ...), expr, ...)


A character pattern, containing expressions to be evaluated in {}-brackets. Double brackets are transformed into a single bracket without evaluating the inner expression. For instance, "var{x + 1}_{{a}}" is transformed into "var2_{a}" for x = 1.


Arbitrary many variable ranges and conditions.


A base expression containing free variables which is evaluated for all combinations of variables.


The free variables in the inner expressions (i.e., the content of the {}-brackets) of expr are evaluated in the same way as expressions in gen.list.

See gen.list for more details on the expr and ... parameters.


The functions gen.list.char and gen.vector.char return lists and vectors of characters.

The functions gen.named.list, gen.named.vector, return lists, vectors, and data frames. The work very similar to their counterparts without ".named". Additionally the vector of characters, induced by str, serves as a vector of names for the generated structures. In case of lists or vectors, the result is a named list or a named vector. For data frames, the names are taken as row names.

See Also

gen.list for explanations on list and vector comprehension, and listcompr for an overview of all list comprehension functions.

  • gen.list.char
  • gen.vector.char
  • gen.named.list
  • gen.named.vector
# sum up 1:i for i in 1:5
gen.named.list("sum_to_{x}", sum(1:x), x = 1:5)

# same as above, but return as text
gen.list.char("sum of 1 to {x} is {sum(1:x)}", x = 1:5)

# }
Documentation reproduced from package listcompr, version 0.1.0, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.