Purpose

When presenting tables in an HTML Rmarkdown report, it is more common to have all tables styled in the same manner. This is an example of all tables having the same style, with a few overridden styles.

This package is meant to implement the concept of a grammar of tables. It allows for a simple formula expression and a data frame to create a rich summary table in a variety of formats. It is designed for extensibility at each step of the process, so that one is not limited by the authors choice of table statistics, output format. The grammar however is an integral part of the package, and as such is not modifiable.

Supposed that further in addition to the lancet style one really wanted a shade of cyan to make the document pop. This was added to the header of this document to make all this magic happen:

 <style type="text/css">
 \```{r, results='asis'}
 cat(custom_css("lancet.css"))
 ```
 .figbody thead
 {
   background: #aaffff !important;
 }
 .figbody tbody .odd
 {
   background: #aaffff !important;
 }
 </style>

Here’s an example similary to summaryM from Hmisc to get us started:

Table 1

html5(summary_table("drug ~ bili[2] + albumin + stage::Categorical + protime + sex + age + spiders", pbc),
      fragment=TRUE, caption = "Hmisc::PBC", id="tbl2")
Hmisc::PBC
ND-penicillamineplacebonot randomizedTest Statistic
154158106
Serum Bilirubin mg/dl4180.721.303.600.801.403.200.721.403.08F2,415 = 0.03,P = 0.9721
Albumin gm/dl4183.343.543.783.213.563.833.123.473.72F2,415 = 2.13,P = 0.1201
Histologic Stage, Ludwig Criteria412χ2
6
=
5.33,
P = 0.5022
    10
.
026
2.6 4154
0
.
076
7.6 12158
0
.
047
4.7 5106
    20
.
208
20.8 32154
0
.
222
22.2 35158
0
.
236
23.6 25106
    30
.
416
41.6 64154
0
.
354
35.4 56158
0
.
330
33.0 35106
    40
.
351
35.1 54154
0
.
348
34.8 55158
0
.
330
33.0 35106
Prothrombin Time sec.41610.010.611.410.010.611.010.110.611.0F2,413 = 0.23,P = 0.7951
sex : female4180
.
903
90.3139154
0
.
867
86.7137158
0
.
925
92.5 98106
χ2
2
=
2.38,
P = 0.3042
Age41841.448.155.843.051.958.946.053.061.0F2,415 = 6.10,P = 0.0021
spiders : present3120
.
292
29.2 45154
0
.
285
28.5 45158
χ2
1
=
0.02,
P = 0.8852
N is the number of non-missing value. 1Kruskal-Wallis test. 2Pearson test

Table 2

x <- round(rnorm(375, 79, 10))
y <- round(rnorm(375, 80,  9))
y[rbinom(375, 1, prob=0.05)] <- NA
attr(x, "label") <- "Global score, 3m"
attr(y, "label") <- "Global score, 12m"
html5(summary_table(1 ~ x+y,
                    data.frame(x=x, y=y),
                    after=hmisc_intercept_cleanup),
      fragment=TRUE, caption="Intercept", id="tbl5")
Intercept
NAll
Global score, 3m375727886
Global score, 12m374738086
N is the number of non-missing value. 1Kruskal-Wallis test. 2Pearson test