'How to generate "pretty" output from the str() function in R

I have a moderate-sized data set that is 1000 rows by 81 columns. I'd like to use the output from str(), but I'd like to present it in a "prettier" way. I've tried things like this:

df %>% str() %>% kableExtra::kbl() %>% kableExtra::kable_minimal()

and

tbl_summary(as.data.frame(str(df)))

but neither works. I'm not married to str() or to any specific package, but that's the kind of summary I'm going for.

In the end, this is intended to generate an HTML file, but I'd like it to work with PDF output as well.

Any ideas on how to do this?



Solution 1:[1]

skimr and gt (or kable, or flextable, or DT, or many other table packages) could also work here:

mtcars |>
  skimr::skim() |>
  gt::gt()

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jon Spring