0.5
, rapport
template inputs
should be defined using YAML syntax. See
deprecated-inputs
for details on old input syntax.
The following sections describe new YAML input definition
style.tpl.inputs(fp, use.header = FALSE)
tpl.find
for details)h
argument The full power of rapport
comes into play with
template inputs. One can match inputs against
dataset variables or custom R
objects. The inputs
provide means of assigning R
objects to
symbol
s in the template evaluation environment.
Inputs themselves do not handle only the template names,
but also provide an extensive set of rules that each
dataset variable/user-provided R
object has to
satisfy. The new YAML input specification takes advantage
of R
class system. The input attributes should
resemble common R
object attributes and methods.
Inputs can be divided into two categories:
data
argument inrapport
call.
Currently,rapport
supports onlydata.frame
objects, but that may change in the (near) future.R
object of an appropriate class (and other input
attributes) to match astandaloneinput.General input attributes
Following attributes are available for all inputs:
name
(character string, required)
- input name. It acts as an identifier for a given input,
and is required as such. Template cannot contain
duplicate names.rapport
inputs currently have
custom naming conventions - seeguess.input.name
for details.label
(character string) - input label. It can be
blank, but it's useful to provide input label asrapport
helpers use that information in plot
labels and/or exported HTML tables. Defaults to empty
string.description
(character string) -
similar tolabel
, but should contain long
description of given input.class
(character string) - defines an input class. Currently
supported input classes are:character
,complex
,factor
,integer
,logical
,numeric
andraw
(all atomic
vector classes are supported). Class attribute should
usually be provided, but it can also beNULL
(default) - in that case the input class will be guessed
based on matchedR
object's value.required
(logical value) - does the input require
a value? Defaults toFALSE
.standalone
(logical value) - indicates that the
input depends on a dataset. Defaults toFALSE
.length
(either an integer value or a named
list with integer values) - provides a set of rules for
input value's length.length
attribute can be
defined via:length: 10
, which sets restriction to exactly 10
vectors or values.min
and/ormax
attributes nested underlength
attribute. This will define a range of values in which
input length must must fall. Note that range limits are
inclusive. Eithermin
ormax
attribute can
be omitted, and they will default to1
andInf
, respectively.rapport
treats input length in a bit
different manner. If you match a subset of 10 character
vectors from the dataset, input length will be10
,
as you might expect. But if you select only one variable,
length will be equal to1
, and not to the number
of vector elements. This stands both for standalone and
dataset inputs. However, if you match a character vector
against a standalone input, length will be stored
correctly - as the number of vector elements.value
(a vector of an appropriate class). This
attribute only exists for standalone inputs. Provided
value must satisfy rules defined inclass
andlength
attributes, as well as any other
class-specific rules (see below).Class-specific attributes
character
nchar
- restricts the number of
characters of the input value. It accepts the same
attribute format aslength
. IfNULL
(default), no checks will be performed.regexp
(character string) - contains a string with
regular expression. If non-NULL
, all strings in a
character vector must match the given regular expression.
Defaults toNULL
- no checks are applied.matchable
(logical value) - ifTRUE
,options
attribute must be provided, whilevalue
is optional, though recommended.options
should contain values to be chosen from,
just like
tag does when nested in
HTML tag, whilevalue
must contain
a value fromoptions
or it can be omitted
(NULL
).allow_multiple
will allow values
fromoptions
list to be matched multiple times.
Note that unlike previous versions ofrapport
,
partial matching is not performed.numeric, integer
limit
- similar tolength
attribute, but allows onlymin
andmax
nested attributes. Unlikelength
attribute,limit
checks input values rather than input
length.limit
attribute isNULL
by default
and the checks are performed only whenlimit
is
defined (non-NULL
).factor
nlevels
- accepts the same format
aslength
attribute, but the check is performed
rather on the number of factor levels.matchable
-ibidas in character inputs
(note that in previous versions ofrapport
matching was performed against factor levels - well, not
any more, now we match against values to make it
consistent withcharacter
inputs).