gen.list.char: Generate Characters and Named Lists, Vectors and Data Frames with List Comprehension
Description
Functions to transform patterns with placeholders into characters or into names of lists, vectors, or data frames,
based on variable ranges and additional conditions.
Usage
gen.list.char(str, ...)
gen.vector.char(str, ...)
gen.named.list(str, expr, ...)
gen.named.vector(str, expr, ...)
gen.named.data.frame(str, expr, ...)
Arguments
str
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.
expr
A base expression containing free variables which is evaluated for all combinations of variables.
Value
The functions gen.list.char and gen.vector.char return lists and vectors of characters.
The functions gen.named.list, gen.named.vector, gen.named.data.frame 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.
Details
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.
See Also
gen.list for explanations on list and vector comprehension,
and listcompr for an overview of all list comprehension functions.
# NOT RUN {# sum up 1:i for i in 1:5gen.named.list("sum_to_{x}", sum(1:x), x = 1:5)
# same as above, but return as textgen.list.char("sum of 1 to {x} is {sum(1:x)}", x = 1:5)
# }