data_list | R Documentation |
Functions used by compose_data()
to create lists of data suitable for
input into a Bayesian modeling function. These functions typically should not be called directly
(instead use compose_data()
), but are exposed for the rare cases in which
you may need to provide your own conversion routines for a data type not already
supported (see Details).
data_list(...)
as_data_list(object, name = "", ...)
## Default S3 method:
as_data_list(object, name = "", ...)
## S3 method for class 'numeric'
as_data_list(object, name = "", scalar_as_array = FALSE, ...)
## S3 method for class 'logical'
as_data_list(object, name = "", ...)
## S3 method for class 'factor'
as_data_list(object, name = "", .n_name = n_prefix("n"), ...)
## S3 method for class 'character'
as_data_list(object, name = "", ...)
## S3 method for class 'list'
as_data_list(object, name = "", ...)
## S3 method for class 'data.frame'
as_data_list(object, name = "", .n_name = n_prefix("n"), ...)
## S3 method for class 'data_list'
as_data_list(object, name = "", ...)
... |
Additional arguments passed to other implementations of
|
object |
The object to convert (see Details). |
name |
The name of the element in the returned list corresponding to this object. |
scalar_as_array |
If |
.n_name |
A function that is used to form variables storing the number of
rows in data frames or the number of levels in factors in |
data_list
creates a list with class c("data_list", "list")
instead of c("list")
, but largely otherwise acts like the list()
function.
as_data_list
recursively translates its first argument into list elements,
concatenating 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(name)
is added with the number of levels in the factor.
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(name)
if name
is not ""
)
is also added containing the number of rows in the data frame.
all other types are dropped (and a warning given)
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.
An object of class c("data_list", "list")
, where each element
is a translated variable as described above.
Matthew Kay
compose_data()
.
# Typically these functions should not be used directly.
# See the compose_data function for examples of how to translate
# data in lists for input to Bayesian modeling functions.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.