Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use list2DF to create a list-column data.frame #169

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

rvalieris
Copy link
Contributor

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
Copy link
Contributor Author

important to note, list2DF was introduced in R 4.0.0, but it is available on the backports package: https://github.com/r-lib/backports

@flying-sheep
Copy link
Member

could you add a test case?

@rvalieris
Copy link
Contributor Author

yes, I just added a commit with tests.
I'm testing all three variations with data.frame, tibble and data.table, but currently it is only failing on tibbles.

@flying-sheep flying-sheep added this pull request to the merge queue Aug 6, 2024
@flying-sheep
Copy link
Member

thanks!

Merged via the queue into IRkernel:main with commit 8809fc9 Aug 6, 2024
2 checks passed
@rvalieris rvalieris deleted the fix branch August 6, 2024 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants