tibble::tibble(name = "my_vec", value = list(c(first = 1L, second = 2L, third = 3L)))
We can see that my_tib_vec and my_tib_list are not the same.
waldo::compare(my_tib_vec, my_tib_list)
`attr(old, 'row.names')`: 1 2 3
`attr(new, 'row.names')`: 1
`old$name`: "first" "second" "third"
`new$name`: "my_vec"
`old$value` is an integer vector (1, 2, 3)
`new$value` is a list
This difference comes from the fact that the enframe() function converts a named vector into a regular tibble, while a list will be transformed into a nested1 tibble.
To obtain the same tibbles, we need to perform operations on the nested tibble. First, we need to unlist the value variable and to enframe it in a list to retrieve the name of each element. Eventually, we can unnest the column value.
Note that we remove the initial name column which contained the name of the list, namely my_vec, to only keep the name variable corresponding to the names of the list values, i.e. "first", "second" and "third".
@online{lettry2024,
author = {Lettry, Layal Christine},
title = {How Can You Use the *Frame Functions from the Package
Tibble?},
date = {2024-08-28},
url = {https://rdiscovery.netlify.app/posts/2024-08-28_frame-functions/},
langid = {en}
}