Tables

Display data in attractive, compact formats

Table of Contents


There are a number of options available for displaying tables within Radix articles, including:

Knitr kable

The knitr::kable() function will render an R data frame as an HTML table. For example:


```{r, layout="l-body-outset"}
library(knitr)
kable(head(mtcars))
```
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1

Often times tables will require more width for their display than the standard Radix article text width. Here we use layout="l-body-outset" to cause the table to outset slightly from the main text column. All of the available figure layouts can also be used with tables.

Paged tables

If a data frame has a large number of rows it might not be practical to display it fully inline. In these situations you can use the rmarkdown::paged_table() function to create a table that allows pagination of rows and columns. For example:


```{r, layout="l-body-outset"}
library(rmarkdown)
paged_table(mtcars)
```

There are a number of options available that control the display of paged tables. By default, 10 rows at a time are displayed but you can use the rows.print option to increase this. For example:


```{r, layout="l-body-outset"}
library(rmarkdown)
paged_table(mtcars, options = list(rows.print = 15))
```

Here is a summary of the available paged table options:

Option Description
rows.print Maximum rows to print per page.
max.print Maximum rows in the table (defaults to 1000).
cols.print Maximum columns in the table (defaults to 10).
rownames.print Print row names as part of the table.

Markdown tables

You can also define tables using markdown. For example, the table from the previous section that describes paged table options was defined with the following markdown:


| Option           | Description                                    |
|------------------|------------------------------------------------|
| `rows.print`     | Maximum rows to print per page.                |
| `max.print`      | Maximum rows in the table (defaults to 1000).  |
| `cols.print`     | Maximum columns in the table (defaults to 10). |
| `rownames.print` | Print row names as part of the table.          |

You can use Radix figure layout classes with markdown tables by enclosing them in markdown div (:::) named with the appropriate class, for example:


::: l-body-outset
| Option           | Description                                    |
|------------------|------------------------------------------------|
| `rows.print`     | Maximum rows to print per page.                |
| `max.print`      | Maximum rows in the table (defaults to 1000).  |
| `cols.print`     | Maximum columns in the table (defaults to 10). |
| `rownames.print` | Print row names as part of the table.          |
:::

Corrections

If you see mistakes or want to suggest changes, please create an issue on the source repository.

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY 4.0. Source code is available at https://github.com/radixpub/radix-r, unless otherwise noted. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".