Applying heddle can leave your template pieces stored as either string objects, vectors (standalone or in a dataframe), or nested vectors (if applied using map()). This function takes those elements and combines them into a single exportable template.
make_template(data, ...)
data | The dataframe containing variables to be combined. |
---|---|
... | The variables to be combined into a template object. |
Returns the collapsed template as a character string.
Other manipulation functions:
create_yaml_header()
,
heddle()
,
provide_parameters()
,
use_parameters()
# When passed vectors, make_template flattens each vector into a single
# string and then combines its arguments from left to right
spList <- data.frame(Species = c(unique(iris$Species), "test string"))
make_template(
heddle(spList, "SPECIES CODE GWAR ", "GWAR" = Species),
heddle(spList, "SPECIES CODE GWAR ", "GWAR" = Species)
)
#> [1] "SPECIES CODE 1 SPECIES CODE 2 SPECIES CODE 3 SPECIES CODE test string SPECIES CODE 1 SPECIES CODE 2 SPECIES CODE 3 SPECIES CODE test string "
# When passed variables in a dataframe, make_template collapses each column
# in turn, then combines the output strings from left to right
spList <- data.frame(Species = c(unique(iris$Species), "test string"))
spList$template <- heddle(spList, "SPECIES CODE GWAR ", "GWAR" = Species)
make_template(spList, template)
#> [1] "SPECIES CODE 1 SPECIES CODE 2 SPECIES CODE 3 SPECIES CODE test string "
make_template(spList, template, template)
#> [1] "SPECIES CODE 1 SPECIES CODE 2 SPECIES CODE 3 SPECIES CODE test string SPECIES CODE 1 SPECIES CODE 2 SPECIES CODE 3 SPECIES CODE test string "
# When passed nested columns, heddlr collapses each cell into a string,
# then collapses each column into a string, and then combines the outputs
# from left to right
make_template(tidyr::nest(spList, nested = template), nested)
#> [1] "SPECIES CODE 1 SPECIES CODE 2 SPECIES CODE 3 SPECIES CODE test string "