This function recursively translates each argument into list elements using
as_data_list()
, merging all resulting lists together. By
default this means that:
numerics are included as-is.
logicals are translated into numeric using as.numeric()
.
factors are translated into numeric using as.numeric()
,
and an additional element named .n_name(argument_name)
is added
with the number of levels in the factor. The default .n_name
function prefixes "n_"
before the factor name; e.g. a factor
named foo
will have an element named n_foo
added containing
the number of levels in foo
.
character vectors are converted into factors then translated into numeric
in the same manner as factors are.
lists are translated by translating all elements of the list
(recursively) and adding them to the result.
data.frames are translated by translating every column of the data.frame
and adding them to the result. A variable named "n"
(or
.n_name(argument_name)
if the data.frame is passed as a named
argument argument_name
) is also added containing the number of rows
in the data frame.
NULL
values are dropped. Setting a named argument to NULL
can be used to drop that item from the resulting list (if an unwanted
element was added to the list by a previous argument, such as a column
from a data frame that is not needed in the model).
all other types are dropped (and a warning given)
As in functions like dplyr::mutate()
, each expression is evaluated in an
environment containing the data list built up so far.
For example, this means that if the first argument to compose_data
is a data frame, subsequent arguments can include direct references to columns
from that data frame. This allows you, for example, to easily use
x_at_y()
to generate indices for nested models.
If you wish to add support for additional types not described above,
provide an implementation of as_data_list()
for the type. See
the implementations of as_data_list.numeric
,
as_data_list.logical
, etc for examples.