Learn R Programming

rsurvstat (version 0.1.4)

.df_to_list_of_lists: Convert a nested dataframe to a multilevel list

Description

Convert a nested dataframe to a multilevel list

Usage

.df_to_list_of_lists(df, ...)

Value

a list of lists

Arguments

df

a nested dataframe

...

Named arguments passed on to .transpose

x

a data.frame or row_list

.fix

collapse or expand names in redundant multi-level row_lists. Either FALSE or a string to join or split the names of the multi-level list by

...

not used

Unit tests

iris_list = .df_to_list_of_lists(datasets::iris) # TODO: iris_list has lost Petal.Length as it is interpreting Petal.Width as # nested item and it overwrites Petal.Length rather than merging with it.

testthat::expect_equal( iris_list[[1]]$Species, iris$Species[[1]] )

mtcars_nest = datasets::mtcars dplyr::mutate(name = rownames(.)) tidyr::nest(details = -c(cyl,gear))

mtcars_list = mtcars_nest

mtcars_unnest = mtcars_list

testthat::expect_equal( mtcars_list[[1]]$details[[1]]$name, mtcars_nest$details[[1]]$name[[1]] )