| Title: | Recombinate Nested Lists to Dataframes |
|---|---|
| Description: | Turns nested lists into data.frames in an orderly manner. |
| Authors: | Peter Hurford [aut, cre], Robert Krzyzanowski [aut] |
| Maintainer: | Peter Hurford <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.1 |
| Built: | 2026-05-24 08:00:34 UTC |
| Source: | https://github.com/cran/recombinator |
Checks if a list has names.
has_names(dat)has_names(dat)
dat |
list. The list to verify. |
boolean. TRUE if the list is named, FALSE otherwise.
This function turns a list of data obtained from the Avant API in
heterogeneous format into a data.frame. Here, heterogeneous refers
to a list of lists with each element being of possibly different size,
but a complete named list of the data for that row.
heterogeneous_recombinator(dat, id = "id")heterogeneous_recombinator(dat, id = "id")
dat |
list. The list of lists to process. Each row is a named list with the names being variable names and the values being respective variable values. |
id |
character. Primary key, by default |
For example,
list(list(variable_one = 1, variable_two = 'a'),
list(variable_one = 2, variable_three = 1))
refers to a data set with three variables with two rows, the first variable
having c(1,2), the second c('a', NA), and the third c(NA, 1).
If the list of lists is not formatted in this way, the function performs
no error handling and will likely return a malformed data.frame.
the formatted data.frame
pre_dataframe <- list(list(variable_one = 1, variable_two = 'a'), list(variable_one = 2, variable_three = 1)) df <- heterogeneous_recombinator(pre_dataframe) # 3 by 2 dataframe w/ c(1,2), c('a', NA), c(NA, 1) in the columns, respectively.pre_dataframe <- list(list(variable_one = 1, variable_two = 'a'), list(variable_one = 2, variable_three = 1)) df <- heterogeneous_recombinator(pre_dataframe) # 3 by 2 dataframe w/ c(1,2), c('a', NA), c(NA, 1) in the columns, respectively.
This function turns a list of data obtained from the Avant API in
homogeneous format into a data.frame. Here, homogeneous refers
to a list of lists with the first element of the list being a character
vector of column names, and subsequent list elements being lists of
values in the correct order and of the same length as the names vector.
homogeneous_recombinator(dat, id = "id")homogeneous_recombinator(dat, id = "id")
dat |
list. The list of lists to process. The first list element is a character vector of variable names, and subsequent elements are lists of variable values ordered by these variable names. |
id |
character. Primary key, by default |
For example,
list(c('variable_one', 'variable_two'), list(1, 'a'), list(2, 'b'))
refers to a data set with two variables with two rows, the first variable
having c(1,2) and the latter having 'a', 'b'.
If the list of lists is not formatted in this way, the function performs
no error handling and will likely return a malformed data.frame.
the formatted data.frame
pre_dataframe <- list(c('variable_one', 'variable_two'), list(1, 'a'), list(2, 'b')) df <- homogeneous_recombinator(pre_dataframe) # 2 by 2 dataframe w/ c(1,2), c('a','b') in the columns, respectively.pre_dataframe <- list(c('variable_one', 'variable_two'), list(1, 'a'), list(2, 'b')) df <- homogeneous_recombinator(pre_dataframe) # 2 by 2 dataframe w/ c(1,2), c('a','b') in the columns, respectively.
Is this heterogeneous data?
is_heterogeneous(dat)is_heterogeneous(dat)
dat |
list. The list to verify. |
boolean. TRUE if the list is heterogeneous, FALSE otherwise.
Is this homogeneous data?
is_homogeneous(dat)is_homogeneous(dat)
dat |
list. The list to verify. |
boolean. TRUE if the list is heterogeneous, FALSE otherwise.
A mini-utility package for turning nested lists into data.frames.
A recombinator attempts to convert a depth 2 nested list into
a data.frame.
recombinator(dat, id = "id")recombinator(dat, id = "id")
dat |
list. The list of lists to process. It can be in homogeneous or heterogeneous format (see the description). |
id |
character. Primary key, by default |
There are two supported formats.
Homogeneous lists A list where the first list element is a character vector giving the names of the data.frame, and the subsequent list elements themselves lists of values.
Heterogeneous lists A list where each element is a named
list of values. In this format, plyr::rbind will be used
to take the union of all names and impute the ones missing
with NA values.
the converted data.frame. If not a list, no changes will be performed.
A warning will be issued if non-standard names (i.e. those containing more than alphanumeric, underscore, and period characters) are used.
Warn if names will be changed when converting to a data.frame.
warn_on_nonstandard_names(data)warn_on_nonstandard_names(data)
data |
list. A list to convert to a data.frame. |
Nothing, but a warning if the names will be
mangled due to R's make.names.