View source: R/collapse-to-string.R
collapse_to_string | R Documentation |
Collapses list columns in a tibble into columns of character scalars.
collapse_to_string(.data, ..., .sep = ", ")
.data |
Input tibble to modify |
... |
One or more unquoted expressions separated by commas (in the style
of |
.sep |
Character scalar to use a separator when collapsing vectors.
Defaults to |
Any non-list columns passed to ...
will be ignored and will
trigger a warning notifying the user that only list columns can be collapsed.
Returns the same tibble as .data
, but any list columns named in
...
will be collapsed to a character column, with a character scalar (or
NA
) for each row.
Cells containing either character
, numeric
, or logical
vectors will
be collapsed to a single string with paste0(collapse = .sep)
.
Cells containing anything else (i.e. lists, nested tibbles, etc.) will
be converted to a string representation of that object via dput()
.
df <- tibble::tibble(
row_num = c(1, 2, 3),
char_list = list(c("foo", "bar"), "baz", c("naw", "dawg")),
num_list = list(c(23, 34, 45), c(-1, -2, -3), NULL),
list_list = list(list(a=1, b=2, c=3), NULL, list(z=-1, y=-2, x=-3))
)
collapse_to_string(df, char_list, num_list, list_list)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.