Describe the bug
When passing a list of dataframes with S3 class vctrs_list_of (e.g., as returned by dplyr::group_split()) to write.xlsx, the resulting Excel file has an unexpected structure. Instead of containing one sheet per list element, each list element ends up in a single cell with all columns concatenated. Only after calling as.list() on the list of class vctrs_list_of, the expected behavior is restored.
To Reproduce
library(dplyr)
library(openxlsx)
data(iris)
iris_list <- iris %>%
group_split(Species)
tmp_file <- temp_xlsx()
# Unexpected
write.xlsx(iris_list, tmp_file)
# Can be fixed by calling as.list() on vctrs_list_of
iris_list2 <- iris %>%
group_split(Species) %>%
as.list()
tmp_file2 <- temp_xlsx()
# Expected
write.xlsx(iris_list2, tmp_file2)
Expected behavior
Excel file is expected to contain one sheet per list element with the columns as the dataframes in the list.
Describe the bug When passing a list of dataframes with S3 class
vctrs_list_of
(e.g., as returned bydplyr::group_split()
) towrite.xlsx
, the resulting Excel file has an unexpected structure. Instead of containing one sheet per list element, each list element ends up in a single cell with all columns concatenated. Only after callingas.list()
on the list of classvctrs_list_of
, the expected behavior is restored.To Reproduce
Expected behavior Excel file is expected to contain one sheet per list element with the columns as the dataframes in the list.
Example files unexpected.xlsx expected.xlsx
Additional context