A template's definition: its kind, the layout it is built on, its few
parameters (tfl_param()) and its body, a function of the parameters'
values and the report's context that returns the report's items. A
company's package calls it when it is loaded (.onLoad()), and so does
a study's spec/templates/<name>.R. The usual body is a tflspec
template's with the company's defaults (tfl_template_params() to
start from, tfl_template_expand() in the body); see
tfl_use_company_templates().
Usage
tfl_template(
name,
kind = c("table", "figure", "listing"),
layout,
params,
body,
label = NULL,
call = NULL,
example = NULL
)Arguments
- name
The template's name (
"acme_demog").- kind
"table","figure"or"listing".- layout
The layout it is built on (
"summary","hierarchical", ...), or its own name for a layout of its own.- params
Its parameters, a list of
tfl_param().- body
function(a, ctx):athe parameters' values by name (the report's, else their defaults),ctxthe report'scodelistsand the study'spopulation(its analysis sets); returnslist(ard = , data = , content = ),contenta list oftfl_item().- label
What it makes, in a few words;
NULLnone.- call
The function a report's program calls for it (the A use);
NULL:tpl_<name>. A company's package exports it, callingtfl_template_run().- example
Its parameters for a try (a named list): what
tfl_test_templates()runs it with, beside the defaults;NULLnone.
Details
A name already registered is replaced, with a message (a company's
demog over tflspec's: the package loaded later wins). A parameter
that ends in the look – the rows a page, column widths, the digits, the
blank rows, the style – is warned about: the study's styles and
defaults say those, and a template parameter would beat them
(tfl_test_templates() finds them).
Examples
tfl_template("my_ages", kind = "table", layout = "summary",
params = list(tfl_param("population", "SAF", doc = "the analysis set's id")),
body = function(a, ctx) tfl_template_expand("summary",
list(population = a$population, variables = "AGE"),
codelists = ctx$codelists, population = ctx$population))
tfl_templates()[, c("name", "package")]
#> name package
#> 1 ae_overview tflspec
#> 2 ae_soc_pt tflspec
#> 3 demog tflspec
#> 4 disposition tflspec
#> 5 hierarchical tflspec
#> 6 km_simple tflspec
#> 7 km_table tflspec
#> 8 lab_shift tflspec
#> 9 listing tflspec
#> 10 my_ages (session)
#> 11 orr tflspec
#> 12 shift tflspec
#> 13 summary tflspec
#> 14 vs_change tflspec