unimplemented type error in 'EncodeElement' when column contains list
Many thanks for developing and maintaining this handy package. Your readme shows how to use in on data.frames comprising vector columns, but unfortunately my data processing is returning a data.frame that includes columns based on lists. When I try to copy such a dataframe to the clipboard it fails with unimplemented type 'list' in 'EncodeElement'
### show environment and package versions
rstudioapi::versionInfo()$version
Sys.getenv("R_PLATFORM")
version$version.string
[1] ‘2024.12.0.467’
[1] "aarch64-apple-darwin23.6.0"
[1] "R version 4.4.2 (2024-10-31)"
> packageVersion("clipr")
[1] ‘0.8.0’
Here is a reprex of my issue:
# try as list columns
list_table <- structure(list(
date = list("05/01/2025", "12/01/2025", "19/01/2025", "26/01/2025", "02/02/2025"),
date_text = list("Sun 5", "Sun 12", "Sun 19", "Sun 26", "Sun 2"),
occasion = list("Intro", "Topic A", "Topic B", "Topic C", "Summary"),
colour = list("White", "White", "Greeen", "Greeen", "White")),
row.names = 1:5, class = "data.frame")
clipr::write_clip(list_table)
This throws the error: Error in (function (x, file = "", append = FALSE, quote = TRUE, sep = " ", :
unimplemented type 'list' in 'EncodeElement'
I have to use the workaround:
# convert the list columns into vectors
fixed_tab <- as.data.frame(lapply(list_table, function(col) {
if (is.list(col)) unlist(col) else col
}))
clipr::write_clip(fixed_tab)
and now because all my lists have been converted to vectors, the data is copied to the clipboard as expected.
This behaviour was not previously documented – could a workaround, fix or option perhaps be accommodated by a future version of your package? Note that unlisting a column could have unexpected impacts with certain structures of data, but one would hope that a data.frame (intended for pasting as a table) actually contains reasonably rectangular data.