Output Nice-Looking Formatted Tables


#1

When I am generating output from an R Markdown document, I often want to output a table of numbers.

The suggestions for formatting tables in the Markdown cheatsheet all seem to be geared at model-output or statistical result-type tables. That’s not what I need.

What I am looking for is a “presentation-friendly” table. More of a business application.

Something that makes it easy to define the format of each column (decimal places, commas, % signs, date formats, etc.) and that lets me define the borders (existence, size, colour) and shading of the tables and its cells. And the width of the table.

A typical example would be a table with 4 columns: Year/Quarter, Count, Amount, Percentage Change. Like 4-12 rows of data.

Does such a thing exist? Does anyone else have this problem, or is it just me? My current painful workaround is to copy the r output to the clipboard, paste into Excel, run a macro to format everything (or do it manually), save that as an image, then link the image into the Rmd file. Ick.


KableExtra --how to create a table with equal column width
Styling advice on layout for tables and graphs, which package is the best?
Getting nice-looking tables wider than a page when rendering to R Markdown HTML
Styling advice on layout for tables and graphs, which package is the best?
FAQ: Tips for Introducing Non-Programming-Problem Discussions
Customizing general objects formatting output
Generate summary table and comparison p values then export to word
Your feedback on a "How to introduce non-programming-problem questions" guide
#2

You could check out the xtable package if you are rendering to a pdf via latex. It is not the easiest package to use if you have never used it before, but once you get the hang of it, it is pretty flexible and allows you to format tables however you want.


#3

I REALLY like the kableExtra package. It leverages all the power of LaTeX (via bookmans) or HTML (via bootstraps) depending on your application in way that let’s you get started very easily. It is the well documented and looks gorgeous.

http://haozhu233.github.io/kableExtra/

HTH,

Sam


Styling advice on layout for tables and graphs, which package is the best?
#4

I’ve been using kable from the knitr package and that is relatively easy to use and looks really nice in RMarkdown documents.


#5

I use formattable to get percent signs in tables. The link to the page for
formattable is here. https://renkun.me/formattable/.


#6

huxtable and pixiedust are also good options for customizing tables. These use the same set of vommands to produce output in both LaTeX and HTML.


#7

At the rOpenSci unconf the group that made the packagemetrics :package: did a demo specifically on table-making packages (tableGallery) which is great! There’s even an ultra-meta formattable table comparing package tables in the packagemetrics blog post.

David Hugh-Jones (author of huxtable) also did a great table comparing table-package features in the Design Principles, Comparisons and Limitations section of the huxtable docs!

(below is just a screenshot, definitely worth taking a look directly)


Tufte-style HTML with table in margin
Wrap column name in pdf table, from knitr::kable
#8

Great stuff here. I’m amazed at how many quality options there are. I’ve just been using knitr::kable for static tables and DT::datatable for interactive tables, but looks like I can pretty easily step up my game!


#9

There is also a the package flextable : https://davidgohel.github.io/flextable
A real helper to format table for reporting with merge cells, header control, size cells control, …
From dataframe in R workspace to this table formatted for reporting needs

image


#10

Awesome stuff. Thanks. This is ultra helpful. Because as much as I try, I just can’t make the knitr kable tables look like I want them too.


#11

Hey, @mara, just a note that the tableGallery link is not working anymore. Maybe that's intended, but just wanted to let you know! Bye


#12

Thanks. Could you file an issue in the packagemetrics repo:

It looks like the files were moved, but the links were never updated. It looks like you can see the tableGallery here, now.


#13

'k, issue submitted! And thanks for the correct link :grinning:


#14

DT has quite a lot more features than listed in this table.


#15

I suggest getting in touch with David Hugh-Jones. Certainly time for an update, especially given the release of 0.2.0 0.4.0. :flushed: If you know which features it has, though, I'm sure a PR would get things up to speed more quickly.


#16

I was just looking into it to try to make an exhaustive list of the features that are missing in the table to submit a PR :slight_smile:


#17

Awesome! Feature comparisons are so valuable (IMHO), and also can be so time consuming– especially since I usually end up switching things up only after getting frustrated spending hours trying to do x a different way in package y!


#18

This topic has been closed.

If you have a query related to it or one of the replies, start a new topic and refer back to here with a link.