Convert a list column to a readable character column.
Source:R/visualizer-lib-utils.R
list_col_to_chr.Rd
Convert a list-type column (typically in a tibble) to a character-type column. Often useful for plotting along this column.
Arguments
- list_col
A list-type column to be converted to character.
- name
Name of column. Used as a prefix in the returned character strings. Default is
NULL
, which adds no prefix.- verbatim
If
TRUE
, paste list contents together into a character vector. IfFALSE
(default), map items in list to unique identifiers (i.e., 1, 2, 3, ...).
Examples
# create example tibble with list columns to convert
plot_tib <- tibble::tibble(a = 1:3,
b = list(1, 2, 3),
c = list(1:2, 3:4, 5:6),
d = list(tibble::tibble(a = 1:3,
b = c(4, 5, 6)),
"abc",
123))
# verbatim = TRUE pastes lists together verbatim
plot_tib_chr_verbatim <- plot_tib %>%
dplyr::mutate(dplyr::across(tidyselect::everything(),
~list_col_to_chr(.x,
name = dplyr::cur_column(),
verbatim = TRUE)))
# verbatim = FALSE maps items in list to unique ids (i.e., 1, 2, 3, ...)
plot_tib_chr <- plot_tib %>%
dplyr::mutate(dplyr::across(tidyselect::everything(),
~list_col_to_chr(.x,
name = dplyr::cur_column(),
verbatim = FALSE)))