Transformers allow you to apply functions to the glue input and output, before and after evaluation. This allows you to write things like glue_sql(), which automatically quotes variables for you or add a syntax for automatically collapsing outputs.

The transformer functions simply take two arguments code and envir, where code is the unparsed string inside the glue block and envir is the environment to execute the code in. Most transformers will then call glue::evaluate(), which takes code and envir and parses and evaluates the code.

You can then supply the transformer function to glue with the .transformer argument. In this way users can define manipulate the code before parsing and change the output after evaluation.

It is often useful to write a glue() wrapper function which supplies a .transformer to glue() or glue_data() and potentially has additional arguments. One important consideration when doing this is to include .envir = parent.frame() in the wrapper to ensure the evaluation environment is correct.

Some examples implementations of potentially useful transformers follow. The aim right now is not to include most of these custom functions within the glue package. Rather users are encouraged to create custom functions using transformers to fit their individual needs.