repr icon indicating copy to clipboard operation
repr copied to clipboard

use list2DF to create a list-column data.frame

Open rvalieris opened this issue 1 year ago • 3 comments

Hello, this is a fix for printing tibbles with list columns.

currently this fails:

> head(dplyr::starwars,3)
ERROR while rich displaying an object: Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 5, 6, 7, 4

this happens because the tbl_col_format function is trying to create a single column data.frame with a list, but list columns on base R are tricky:

> data.frame(list(a=1:3, b=list(1:1, 1:2, 1:3)))
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  :
  arguments imply differing number of rows: 1, 2, 3

you need to use the list2DF function instead:

> list2DF(list(a=1:3, b=list(1:1, 1:2, 1:3)))
  a       b
1 1       1
2 2    1, 2
3 3 1, 2, 3

rvalieris avatar Jul 20 '24 16:07 rvalieris