Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print tibble with column breaks as in v1.3.0

Tags:

r

tidyverse

Using the latest version of tibble the output of wide tibbles is not properly displayed when setting width = Inf.

Based on my tests with previous versions wide tibbles were printed nicely until versions later than 1.3.0. This is what I would like the output to be printed like:

tibble_ok

...but this is what it looks like using the latest version of tibble:

tibble_broken

I tinkered around with the old sources but to no avail. I would like to incorporate this in a package so the solution should pass R CMD check. When I just copied a load of functions from tibble v1.3.0 I managed to restore the old behavior but could not pass the check.

There's an open issue on Github related to this problem but it's apparently 'not high priority'. Is there a way to print tibbles properly with the new version?

like image 606
thie1e Avatar asked Jun 29 '17 17:06

thie1e


1 Answers

Try out this function:

print_width_inf <- function(df, n = 6) {
  df %>%
    head(n = n) %>%
    as.data.frame() %>%
    tibble:::shrink_mat(width = Inf, rows = NA, n = n, star = FALSE) %>%
    `[[`("table") %>%
    print()
}
like image 73
F. Privé Avatar answered Oct 07 '22 21:10

F. Privé