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

head(pbc)
##   bili albumin stage protime    sex fu.days      age spiders hepatom
## 1 14.5    2.60     4    12.2 female     400 58.76523 present present
## 2  1.1    4.14     3    10.6 female    4500 56.44627 present present
## 3  1.4    3.48     4    12.0   male    1012 70.07255  absent  absent
## 4  1.8    2.54     4    10.3 female    1925 54.74059 present present
## 5  3.4    3.53     3    10.9 female    1504 38.10541 present present
## 6  0.8    3.98     3    11.0 female    2503 66.25873  absent present
##   ascites alk.phos   sgot chol trig platelet            drug status
## 1 present   1718.0 137.95  261  172      190         placebo      1
## 2  absent   7394.8 113.52  302   88      221         placebo      0
## 3  absent    516.0  96.10  176   55      151         placebo      1
## 4  absent   6121.8  60.63  244   92      183         placebo      1
## 5  absent    671.0 113.15  279   72      136 D-penicillamine      0
## 6  absent    944.0  93.00  248   63       NA D-penicillamine      1
##                            edema copper
## 1 edema despite diuretic therapy    156
## 2                       no edema     54
## 3     edema, no diuretic therapy    210
## 4     edema, no diuretic therapy     64
## 5                       no edema    143
## 6                       no edema     50
html5(tangram("drug ~ bili[2] + albumin + stage::Categorical + protime + sex + age + spiders", tangram::pbc),
      fragment=TRUE, caption = "Hmisc::PBC", id="tbl2")
Hmisc::PBC
ND-penicillamineplacebonot randomizedTest Statistic
154158106
Serum Bilirubinmg/dl4180.701.303.600.801.403.220.701.403.12F2,415 = 0.03,P = 0.9721
Albumingm/dl4183.343.543.783.213.563.833.123.473.73F2,415 = 2.13,P = 0.1201
Histologic Stage, Ludwig Criteria412χ2
6
=
5.33,
P = 0.5022
        10
.
026
2.597 4154
0
.
076
7.595 12158
0
.
050
5.000 5100
        20
.
208
20.779 32154
0
.
222
22.152 35158
0
.
250
25.000 25100
        30
.
416
41.558 64154
0
.
354
35.443 56158
0
.
350
35.000 35100
        40
.
351
35.065 54154
0
.
348
34.810 55158
0
.
350
35.000 35100
Prothrombin Timesec.41610.010.611.410.010.611.010.110.611.0F2,413 = 0.23,P = 0.7951
sex : female4180
.
903
90.260139154
0
.
867
86.709137158
0
.
925
92.453 98106
χ2
2
=
2.38,
P = 0.3042
Age41841.448.155.842.951.959.046.053.061.1F2,415 = 6.10,P = 0.0021
spiders : present3120
.
292
29.221 45154
0
.
285
28.481 45158
χ2
1
=
0.02,
P = 0.8852
N is the number of non-missing value. 1Kruskal-Wallis. 2Pearson. 3Wilcoxon.

Table 2

set.seed(1234)
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(tangram(1 ~ x+y,
                    data.frame(x=x, y=y),
                    after=hmisc_intercept_cleanup),
      fragment=TRUE, caption="Intercept", id="tbl5")
Intercept
NAll
Global score, 3m375737985
Global score, 12m374738085
N is the number of non-missing value. 1Kruskal-Wallis. 2Pearson. 3Wilcoxon.