From b8d96b30a3320d729c7b883c2ab0133cc31f542f Mon Sep 17 00:00:00 2001 From: vincentarelbundock Date: Sat, 20 Jan 2024 22:45:29 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20vincenta?= =?UTF-8?q?relbundock/tinytable@aa02ad0bd39a7f519553a93ce0b74b8532a8a644?= =?UTF-8?q?=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- freeze.rds | Bin 361 -> 361 bytes man/format_tt.html | 56 +- man/group_tt.html | 2 +- man/style_bootstrap.html | 2 +- man/style_tt.html | 2 +- man/tt.html | 106 +- search.json | 58 +- vignettes/tutorial.html | 3272 ++++++++++---------------------------- vignettes/tutorial.pdf | Bin 127662 -> 127661 bytes 9 files changed, 905 insertions(+), 2593 deletions(-) diff --git a/freeze.rds b/freeze.rds index 6c3e345ceec333e5cedc4223b83ff4560539406d..30b48926d4988553e17fceac834db8643c75543c 100644 GIT binary patch literal 361 zcmV-v0hazBiwFP!0000016`20POLEug~KcoPyp2xB`*MEaT2>k0y-K55*@O$AOy28 z^Is%h9+4UNhoy@1o#P|hce_fdp&AVbYB+AC8sFYr9-~r&gZ9~0Bem1sBgqjVyHZjh zs09r;B#kyCZ4oid6TTdNC{ zlXhIC);4L}#X`6U*)@I42_k|1@!s-e-iUSjC5CXQL8bp+=)M(Ir zTVMY1lqY4`il4{by}md*zq&YindC2WFyZNGoh>HZ-FMx|bNSiaQ8TU>sX%4@to5WKa_8MXRWUrlzRUF(PnjE HJpup#iPxiO literal 361 zcmV-v0hazBiwFP!0000016`0!PvjvC#&KSf)q{H4c-$|bLMc#=Cb~B-MiXzQP%uX4 z#hL$__~nhvxWpGOw9oTvDZSlON{!WIJW}In3)S@I`tLC*H9Bm`FEvrS?f#P_5Q;4& z`-ruWK}%5+_^cr#+s@VC$WQ>6kO&J!M#KuyVyG?#-#N`SC)Dh~3ShPf3|bsr&9x6_Xw0SV*Vfs|SxFrgKJD&7z4aIbAc<(E5fptkLa|?i_$=hJf)U7H`{3 z1P(%~R-!mBohuOuGH8x5qa+s*P5X(97C@4e&UryWzuAHg$)X9>r-%%`8X`)f)MV7S zo&WrF&a<*^!Pn*PU0s}=UtXL%&-(L+GoGK;#cIaG-7uV7b^TzY->(+`mfz(4jlAZU z@=g7{RfpH7a+em1VLhyP`J>f``?ct3BM%Sr*MZYhIbL#pExamples num_mark_dec = ",", num_mark_big = " ") tt(tab) -
-
Called from: tt_bootstrap(x = list(a = c("10 001", "10 000", "10 000"), b = c(" 9 999", 
-" 9 999", "10 001")), caption = NULL, theme = "default", width = NULL, 
-    notes = NULL, placement = NULL)
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
@@ -443,7 +413,7 @@

Examples

- tinytable_o4gmfgrhoeazu3tdxksw + tinytable_4jnwouda9otcsbw5oret @@ -463,7 +433,7 @@

Examples

- +
@@ -475,14 +445,14 @@

Examples

- + - - + + - + @@ -491,20 +461,12 @@

Examples

@@ -877,7 +730,7 @@

Alignment

-
10 001 9 99910 002
10 000 9 99910 00110 002
10 000 9 999 10 001
+
@@ -909,20 +762,12 @@

Alignment

-
tt(dat) |> style_tt(j = 1:3, align = "lcr")
-
-
Called from: tt_bootstrap(x = list(a = c("a", "aa", "aaa"), b = c("b", "bb", 
-"bbb"), c = c("c", "cc", "ccc")), caption = NULL, theme = "default", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(dat) |> style_tt(j = 1:3, align = "lcr")
@@ -983,12 +798,12 @@

Alignment

- tinytable_ai9064etgz4mpsax6q5e + tinytable_6drxk5g76kv2rhf4j0tg @@ -1006,7 +821,7 @@

Alignment

-
+
@@ -1038,20 +853,12 @@

Alignment

@@ -1084,44 +891,13 @@

Form

The tt() function is minimalist; it’s inteded purpose is simply to draw nice tables. Users who want to format numbers, dates, strings, and other variables in different ways should process their data before supplying it to the tt() table-drawing function. To do so, we can use the format_tt() function supplied by the tinytable.

In a very simple case—such as printing 2 significant digits of all numeric variables—we can use the digits argument of tt():

-
dat <- data.frame(
-     w = c(143002.2092, 201399.181, 100188.3883),
-     x = c(1.43402, 201.399, 0.134588),
-     y = as.Date(sample(1:1000, 3)),
-     z = c(TRUE, TRUE, FALSE))
-
-tt(dat, digits = 2)
-
-
Called from: tt_bootstrap(x = list(w = c("143002", "201399", "100188"), x = c("  1.43", 
-"201.40", "  0.13"), y = c("1971-06-01", "1971-03-08", "1971-04-25"
-), z = c("True", "True", "False")), caption = NULL, theme = "default", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
dat <- data.frame(
+     w = c(143002.2092, 201399.181, 100188.3883),
+     x = c(1.43402, 201.399, 0.134588),
+     y = as.Date(sample(1:1000, 3)),
+     z = c(TRUE, TRUE, FALSE))
+
+tt(dat, digits = 2)
@@ -1129,7 +905,7 @@

Form - tinytable_384ihffp3wcku09li564 + tinytable_rh2wcoa984obhq4jz2x2 @@ -1149,7 +925,7 @@

Form
-

+
@@ -1164,19 +940,19 @@

Form

- + - + - + @@ -1185,20 +961,12 @@

Form @@ -2481,7 +1867,7 @@

Math

-
143002 1.431971-06-011970-05-11 True
201399 201.401971-03-081972-07-19 True
100188 0.131971-04-251971-04-29 False
+
@@ -2502,20 +1888,12 @@

Math

@@ -2562,43 +1940,12 @@

Style

Cells, rows, columns

To style individual cells, we use the style_cell() function. The first two arguments—i and j—identify the cells of interest, by row and column numbers respectively. To style a cell in the 2nd row and 3rd column, we can do:

-
tt(x) |>
-  style_tt(
-    i = 2,
-    j = 3,
-    background = "black",
-    color = "white")
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4), cyl = c(6, 
-6, 4, 6), disp = c(160, 160, 108, 258), hp = c(110, 110, 93, 
-110), drat = c(3.9, 3.9, 3.85, 3.08)), caption = NULL, theme = "default", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(x) |>
+  style_tt(
+    i = 2,
+    j = 3,
+    background = "black",
+    color = "white")
@@ -2606,10 +1953,10 @@

Cells, rows, columns - tinytable_qmip6x1cd1345mmfha6t + tinytable_cbqzo4vvfz55bxt3zzy9 @@ -2627,7 +1974,7 @@

Cells, rows, columns -

+
@@ -2674,20 +2021,12 @@

Cells, rows, columns @@ -2705,43 +2044,12 @@

Cells, rows, columns

The i and j accept vectors of integers to modify several cells at once:

-
tt(x) |>
-  style_tt(
-    i = 2:3,
-    j = c(1, 3, 4),
-    italic = TRUE,
-    color = "orange")
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4), cyl = c(6, 
-6, 4, 6), disp = c(160, 160, 108, 258), hp = c(110, 110, 93, 
-110), drat = c(3.9, 3.9, 3.85, 3.08)), caption = NULL, theme = "default", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(x) |>
+  style_tt(
+    i = 2:3,
+    j = c(1, 3, 4),
+    italic = TRUE,
+    color = "orange")
@@ -2749,10 +2057,10 @@

Cells, rows, columns - tinytable_0e3d8frmpdge8gae6slq + tinytable_9n3zozrgu19ombv9m82i @@ -2770,7 +2078,7 @@

Cells, rows, columns -

+
@@ -2817,20 +2125,12 @@

Cells, rows, columns @@ -2853,38 +2153,7 @@

Cells, rows, columns

We can style all cells in a table by omitting both the i and j arguments:

-
tt(x) |> style_tt(color = "orange")
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4), cyl = c(6, 
-6, 4, 6), disp = c(160, 160, 108, 258), hp = c(110, 110, 93, 
-110), drat = c(3.9, 3.9, 3.85, 3.08)), caption = NULL, theme = "default", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(x) |> style_tt(color = "orange")
@@ -2892,10 +2161,10 @@

Cells, rows, columns - tinytable_paciktzxipdmnqau17w4 + tinytable_2snr3tqn4xnp9conh3ya @@ -2913,7 +2182,7 @@

Cells, rows, columns -

+
@@ -2960,20 +2229,12 @@

Cells, rows, columns @@ -3010,38 +2271,7 @@

Cells, rows, columns

We can style entire rows by omitting the j argument:

-
tt(x) |> style_tt(i = 1:2, color = "orange")
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4), cyl = c(6, 
-6, 4, 6), disp = c(160, 160, 108, 258), hp = c(110, 110, 93, 
-110), drat = c(3.9, 3.9, 3.85, 3.08)), caption = NULL, theme = "default", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(x) |> style_tt(i = 1:2, color = "orange")
@@ -3049,10 +2279,10 @@

Cells, rows, columns - tinytable_gguzxf310z41emj1uadx + tinytable_8jsi3ou34cb1nreoazg7 @@ -3070,7 +2300,7 @@

Cells, rows, columns -

+
@@ -3117,20 +2347,12 @@

Cells, rows, columns @@ -3157,38 +2379,7 @@

Cells, rows, columns

We can style entire columns by omitting the i argument:

-
tt(x) |> style_tt(j = c(2, 4), bold = TRUE)
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4), cyl = c(6, 
-6, 4, 6), disp = c(160, 160, 108, 258), hp = c(110, 110, 93, 
-110), drat = c(3.9, 3.9, 3.85, 3.08)), caption = NULL, theme = "default", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(x) |> style_tt(j = c(2, 4), bold = TRUE)
@@ -3196,10 +2387,10 @@

Cells, rows, columns - tinytable_iau5p13mjznznrlgil20 + tinytable_oflckwyxt6rku4r54eig @@ -3217,7 +2408,7 @@

Cells, rows, columns -

+
@@ -3264,20 +2455,12 @@

Cells, rows, columns @@ -3304,38 +2487,7 @@

Cells, rows, columns

The j argument accepts integer vectors, but also a string with a Perl-style regular expression, which makes it easier to select columns by name:

-
tt(x) |> style_tt(j = "mpg|drat", color = "orange")
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4), cyl = c(6, 
-6, 4, 6), disp = c(160, 160, 108, 258), hp = c(110, 110, 93, 
-110), drat = c(3.9, 3.9, 3.85, 3.08)), caption = NULL, theme = "default", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(x) |> style_tt(j = "mpg|drat", color = "orange")
@@ -3343,10 +2495,10 @@

Cells, rows, columns - tinytable_ey88ffpqeu8kigftto6v + tinytable_gdhv9y9019mnylyq33q0 @@ -3364,7 +2516,7 @@

Cells, rows, columns -

+
@@ -3411,20 +2563,12 @@

Cells, rows, columns @@ -3451,40 +2595,9 @@

Cells, rows, columns

Of course, we can also call the style_tt() function several times to apply different styles to different parts of the table:

-
tt(x) |> 
-  style_tt(i = 1, j = 1:2, color = "orange") |>
-  style_tt(i = 1, j = 3:4, color = "green")
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4), cyl = c(6, 
-6, 4, 6), disp = c(160, 160, 108, 258), hp = c(110, 110, 93, 
-110), drat = c(3.9, 3.9, 3.85, 3.08)), caption = NULL, theme = "default", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(x) |> 
+  style_tt(i = 1, j = 1:2, color = "orange") |>
+  style_tt(i = 1, j = 3:4, color = "green")
@@ -3492,11 +2605,11 @@

Cells, rows, columns - tinytable_mcz18amrpo48m704ct75 + tinytable_r87aor4hd2cjv9uk8jgk @@ -3514,7 +2627,7 @@

Cells, rows, columns -

+
@@ -3561,20 +2674,12 @@

Cells, rows, columns @@ -3611,38 +2716,7 @@

Colors

Note that the keywords used in LaTeX and HTML are slightly different.

-
tt(x) |> style_tt(i = 1:4, j = 1, color = "#FF5733")
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4), cyl = c(6, 
-6, 4, 6), disp = c(160, 160, 108, 258), hp = c(110, 110, 93, 
-110), drat = c(3.9, 3.9, 3.85, 3.08)), caption = NULL, theme = "default", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(x) |> style_tt(i = 1:4, j = 1, color = "#FF5733")
@@ -3650,10 +2724,10 @@

Colors

- tinytable_xws1a0wnhpajp10lty11 + tinytable_jmgtcn8c4myi6nvtvwu2 @@ -3671,7 +2745,7 @@

Colors

-
+
@@ -3718,20 +2792,12 @@

Colors

@@ -3756,38 +2822,7 @@

Colors

Fonts

The font size is specified in terms of pt units, where 1pt=1.333px:

-
tt(x) |> style_tt(j = "mpg|hp|qsec", fontsize = 18)
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4), cyl = c(6, 
-6, 4, 6), disp = c(160, 160, 108, 258), hp = c(110, 110, 93, 
-110), drat = c(3.9, 3.9, 3.85, 3.08)), caption = NULL, theme = "default", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(x) |> style_tt(j = "mpg|hp|qsec", fontsize = 18)
@@ -3795,10 +2830,10 @@

Fonts

- tinytable_mimwl8cs352g516a38l9 + tinytable_6zs2xnlz8m200jsfzf3r @@ -3816,7 +2851,7 @@

Fonts

-
+
@@ -3863,20 +2898,12 @@

Fonts

@@ -3906,38 +2933,9 @@

Fonts

Headers

The header can be omitted from the table by deleting the column names in the x data frame:

-
k <- x
-colnames(k) <- NULL
-tt(k)
-
-
Called from: tt_bootstrap(x = list(c(21, 21, 22.8, 21.4), c(6, 6, 4, 6), c(160, 
-160, 108, 258), c(110, 110, 93, 110), c(3.9, 3.9, 3.85, 3.08)), 
-    caption = NULL, theme = "default", width = NULL, notes = NULL, 
-    placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- NULL
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
k <- x
+colnames(k) <- NULL
+tt(k)
@@ -3945,7 +2943,7 @@

Headers

- tinytable_bnlnhgmaguj0m36r1gu3 + tinytable_4st4ldvj69jw7moq6xzg @@ -3965,7 +2963,7 @@

Headers

-
+
@@ -4005,20 +3003,12 @@

Headers

@@ -4096,7 +3055,7 @@

Headers

-
+
@@ -4143,20 +3102,12 @@

Headers

@@ -4178,38 +3129,7 @@

Headers

When styling columns without specifying i, the headers are styled in accordance with the rest of the column:

-
tt(x) |> style_tt(j = 2:3, color = "white", background = "black")
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4), cyl = c(6, 
-6, 4, 6), disp = c(160, 160, 108, 258), hp = c(110, 110, 93, 
-110), drat = c(3.9, 3.9, 3.85, 3.08)), caption = NULL, theme = "default", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(x) |> style_tt(j = 2:3, color = "white", background = "black")
@@ -4217,10 +3137,10 @@

Headers

- tinytable_qp2la3kk98ta7vmst7sm + tinytable_ts7j8iz2e5ymbxy1ioo6 @@ -4238,7 +3158,7 @@

Headers

-
+
@@ -4285,20 +3205,12 @@

Headers

@@ -4328,44 +3240,13 @@

Headers

Conditional styling

We can use the standard which function from Base R to create indices and apply conditional stying on rows. And we can use a regular expression in j to apply conditional styling on columns:

-
k <- mtcars[1:10, c("mpg", "am", "vs")]
-
-tt(k) |> 
-  style_tt(
-    i = which(k$am == k$vs),
-    background = "teal",
-    color = "white")
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4, 18.7, 18.1, 
-14.3, 24.4, 22.8, 19.2), am = c(1, 1, 1, 0, 0, 0, 0, 0, 0, 0), 
-    vs = c(0, 0, 1, 1, 0, 1, 0, 1, 1, 1)), caption = NULL, theme = "default", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
k <- mtcars[1:10, c("mpg", "am", "vs")]
+
+tt(k) |> 
+  style_tt(
+    i = which(k$am == k$vs),
+    background = "teal",
+    color = "white")
@@ -4373,10 +3254,10 @@

Conditional styling - tinytable_v2wuq4qjazovxfu0pvoy + tinytable_wl2jtg4g9qcza2nrycum @@ -4394,7 +3275,7 @@

Conditional styling -

+
@@ -4461,20 +3342,12 @@

Conditional styling @@ -4503,41 +3376,10 @@

Conditional stylingVectorized styling (heatmaps)

The color, background, and fontsize arguments are vectorized. This allows easy specification of different colors in a single call:

-
tt(x) |>
-  style_tt(
-    i = 1:4,
-    color = c("red", "blue", "green", "orange"))
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4), cyl = c(6, 
-6, 4, 6), disp = c(160, 160, 108, 258), hp = c(110, 110, 93, 
-110), drat = c(3.9, 3.9, 3.85, 3.08)), caption = NULL, theme = "default", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(x) |>
+  style_tt(
+    i = 1:4,
+    color = c("red", "blue", "green", "orange"))
@@ -4545,13 +3387,13 @@

Vectorized sty - tinytable_swot6zjxeaxpmc266zdg + tinytable_jqhegryieonklmxwtagv @@ -4569,7 +3411,7 @@

Vectorized sty
-

+
@@ -4616,20 +3458,12 @@

Vectorized sty @@ -4666,42 +3500,11 @@

Vectorized sty

When using a single value for a vectorized argument, it gets applied to all values:

-
tt(x) |>
-  style_tt(
-    j = 2:3,
-    color = c("orange", "green"),
-    background = "black")
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4), cyl = c(6, 
-6, 4, 6), disp = c(160, 160, 108, 258), hp = c(110, 110, 93, 
-110), drat = c(3.9, 3.9, 3.85, 3.08)), caption = NULL, theme = "default", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(x) |>
+  style_tt(
+    j = 2:3,
+    color = c("orange", "green"),
+    background = "black")
@@ -4709,11 +3512,11 @@

Vectorized sty - tinytable_knuzs2apt8bqxizpxqso + tinytable_gj5nlp2co7effaojexof @@ -4731,7 +3534,7 @@

Vectorized sty
-

+
@@ -4778,20 +3581,12 @@

Vectorized sty @@ -4818,50 +3613,23 @@

Vectorized sty

We can also produce more complex heatmap-like tables:

-
# A table without header
-k <- data.frame(matrix(1:20, ncol = 5))
-colnames(k) <- NULL
-
-# 20 levels of Inferno colors
-bg <- hcl.colors(20, "Inferno")
-fg <- ifelse(as.matrix(k) < 17, tail(bg, 1), head(bg, 1))
-fs <- 1:20
-
-tt(k, width = .5, theme = "void") |>
-  style_tt(j = 1:5, align = "ccccc") |>
-  style_tt(
-    i = 1:4,
-    j = 1:5,
-    color = fg,
-    background = bg,
-    fontsize = fs)
-
-
Called from: tt_bootstrap(x = list(1:4, 5:8, 9:12, 13:16, 17:20), caption = NULL, 
-    theme = "void", width = 0.5, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- NULL
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
# A table without header
+k <- data.frame(matrix(1:20, ncol = 5))
+colnames(k) <- NULL
+
+# 20 levels of Inferno colors
+bg <- hcl.colors(20, "Inferno")
+fg <- ifelse(as.matrix(k) < 17, tail(bg, 1), head(bg, 1))
+fs <- 1:20
+
+tt(k, width = .5, theme = "void") |>
+  style_tt(j = 1:5, align = "ccccc") |>
+  style_tt(
+    i = 1:4,
+    j = 1:5,
+    color = fg,
+    background = bg,
+    fontsize = fs)
@@ -4869,30 +3637,30 @@

Vectorized sty - tinytable_w9yynimtbvp2agj4ru29 + tinytable_f7bsqp20cecj26zhzpj2 @@ -4910,7 +3678,7 @@

Vectorized sty
-

+
@@ -4950,20 +3718,12 @@

Vectorized sty @@ -5027,49 +3787,13 @@

Groups and labels

Rows

The i argument accepts a named list of integers. The numbers identify the positions where row group labels are to be inserted. The names includes the text that should be inserted:

-
dat <- mtcars[1:9, 1:8]
-
-tt(dat) |>
-  group_tt(i = list(
-    "I like (fake) hamburgers" = 3,
-    "She prefers halloumi" = 4,
-    "They love tofu" = 7))
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4, 18.7, 18.1, 
-14.3, 24.4, 22.8), cyl = c(6, 6, 4, 6, 8, 6, 8, 4, 4), disp = c(160, 
-160, 108, 258, 360, 225, 360, 146.7, 140.8), hp = c(110, 110, 
-93, 110, 175, 105, 245, 62, 95), drat = c(3.9, 3.9, 3.85, 3.08, 
-3.15, 2.76, 3.21, 3.69, 3.92), wt = c(2.62, 2.875, 2.32, 3.215, 
-3.44, 3.46, 3.57, 3.19, 3.15), qsec = c(16.46, 17.02, 18.61, 
-19.44, 17.02, 20.22, 15.84, 20, 22.9), vs = c(0, 0, 1, 1, 0, 
-1, 0, 1, 1)), caption = NULL, theme = "default", width = NULL, 
-    notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
dat <- mtcars[1:9, 1:8]
+
+tt(dat) |>
+  group_tt(i = list(
+    "I like (fake) hamburgers" = 3,
+    "She prefers halloumi" = 4,
+    "They love tofu" = 7))
@@ -5077,11 +3801,11 @@

Rows

- tinytable_9o8ch3av4vjkved6lcsf + tinytable_5eflw8pk9pllpnwsgjsy @@ -5099,7 +3823,7 @@

Rows

-
+
@@ -5211,20 +3935,12 @@

Rows

@@ -5264,54 +3980,18 @@

Rows

We can style group rows in the same way as regular rows:

-
tt(dat) |> 
-  group_tt(
-    i = list(
-      "I like (fake) hamburgers" = 3,
-      "She prefers halloumi" = 4,
-      "They love tofu" = 7)) |>
-  style_tt(
-    i = c(3, 5, 9),
-    align = "c",
-    color = "white",
-    background = "gray",
-    bold = TRUE)
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4, 18.7, 18.1, 
-14.3, 24.4, 22.8), cyl = c(6, 6, 4, 6, 8, 6, 8, 4, 4), disp = c(160, 
-160, 108, 258, 360, 225, 360, 146.7, 140.8), hp = c(110, 110, 
-93, 110, 175, 105, 245, 62, 95), drat = c(3.9, 3.9, 3.85, 3.08, 
-3.15, 2.76, 3.21, 3.69, 3.92), wt = c(2.62, 2.875, 2.32, 3.215, 
-3.44, 3.46, 3.57, 3.19, 3.15), qsec = c(16.46, 17.02, 18.61, 
-19.44, 17.02, 20.22, 15.84, 20, 22.9), vs = c(0, 0, 1, 1, 0, 
-1, 0, 1, 1)), caption = NULL, theme = "default", width = NULL, 
-    notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(dat) |> 
+  group_tt(
+    i = list(
+      "I like (fake) hamburgers" = 3,
+      "She prefers halloumi" = 4,
+      "They love tofu" = 7)) |>
+  style_tt(
+    i = c(3, 5, 9),
+    align = "c",
+    color = "white",
+    background = "gray",
+    bold = TRUE)
@@ -5319,12 +3999,12 @@

Rows

- tinytable_2ghcsme827glsskyrslp + tinytable_scm5wd7ckw273391iyju @@ -5342,7 +4022,7 @@

Rows

-
+
@@ -5454,20 +4134,12 @@

Rows

@@ -5534,48 +4206,12 @@

Rows

Columns

The syntax for column groups is very similar, but we use the j argument instead. The named list specifies the labels to appear in column-spanning labels, and the values must be a vector of consecutive and non-overlapping integers that indicate which columns are associated to which labels:

-
tt(dat) |> 
-  group_tt(
-    j = list(
-      "Hamburgers" = 1:3,
-      "Halloumi" = 4:5,
-      "Tofu" = 7))
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4, 18.7, 18.1, 
-14.3, 24.4, 22.8), cyl = c(6, 6, 4, 6, 8, 6, 8, 4, 4), disp = c(160, 
-160, 108, 258, 360, 225, 360, 146.7, 140.8), hp = c(110, 110, 
-93, 110, 175, 105, 245, 62, 95), drat = c(3.9, 3.9, 3.85, 3.08, 
-3.15, 2.76, 3.21, 3.69, 3.92), wt = c(2.62, 2.875, 2.32, 3.215, 
-3.44, 3.46, 3.57, 3.19, 3.15), qsec = c(16.46, 17.02, 18.61, 
-19.44, 17.02, 20.22, 15.84, 20, 22.9), vs = c(0, 0, 1, 1, 0, 
-1, 0, 1, 1)), caption = NULL, theme = "default", width = NULL, 
-    notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(dat) |> 
+  group_tt(
+    j = list(
+      "Hamburgers" = 1:3,
+      "Halloumi" = 4:5,
+      "Tofu" = 7))
@@ -5583,7 +4219,7 @@

Columns

- tinytable_zkcxa99a5ldy1t665ykm + tinytable_7hsjpfour8t0eq0xzkwd @@ -5603,7 +4239,7 @@

Columns

-
+
@@ -5720,20 +4356,12 @@

Columns

@@ -5832,7 +4424,7 @@

Columns

-
Hamburgers Halloumi
+
@@ -5949,20 +4541,12 @@

Columns

@@ -6041,38 +4625,7 @@

Themes

The Bootstrap framework provides a number of built-in themes to style tables. To use them, we call bootstrapOptions() with the class argument, and we specify the Bootstrap class. A list of available Bootstrap classes can be found here: https://getbootstrap.com/docs/5.3/content/tables/

For example, to produce a “dark” table, we use the table-dark class:

-
tt(x, theme = "table table-dark")
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4), cyl = c(6, 
-6, 4, 6), disp = c(160, 160, 108, 258), hp = c(110, 110, 93, 
-110), drat = c(3.9, 3.9, 3.85, 3.08)), caption = NULL, theme = "table table-dark", 
-    width = NULL, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
tt(x, theme = "table table-dark")
@@ -6080,7 +4633,7 @@

Themes

- tinytable_ehjb3wi17lqtl78rok9v + tinytable_40siifkbrd80g5lb7hln @@ -6100,7 +4653,7 @@

Themes

-
Hamburgers Halloumi
+
@@ -6147,20 +4700,12 @@

Themes

@@ -6379,7 +4854,7 @@

CSS declarations

-
+
@@ -6426,20 +4901,12 @@

CSS declarations

@@ -6464,74 +4931,43 @@

CSS declarations

CSS rules

For more extensive customization, we can use complete CSS rules. In this example, we define several rules that apply to a new class called mytable. Then, we use the theme argument of the tt() function to ensure that our tiny table is of class mytable. Finally, we call style_bootstrap() to apply the rules with the bootstrap_css_rule argument.

-
css_rule <- "
-.mytable {
-  background: linear-gradient(45deg, #EA8D8D, #A890FE);
-  width: 600px;
-  border-collapse: collapse;
-  overflow: hidden;
-  box-shadow: 0 0 20px rgba(0,0,0,0.1);
-}
-
-.mytable th,
-.mytable td {
-  padding: 5px;
-  background-color: rgba(255,255,255,0.2);
-  color: #fff;
-}
-
-.mytable tbody tr:hover {
-  background-color: rgba(255,255,255,0.3);
-}
-
-.mytable tbody td:hover:before {
-  content: '';
-  position: absolute;
-  left: 0;
-  right: 0;
-  top: -9999px;
-  bottom: -9999px;
-  background-color: rgba(255,255,255,0.2);
-  z-index: -1;
-}
-"
-
-tt(x, theme = "table mytable", width = 2/3) |> 
-  style_tt(
-    j = 1:5,
-    align = "ccccc",
-    bootstrap_css_rule = css_rule)
-
-
Called from: tt_bootstrap(x = list(mpg = c(21, 21, 22.8, 21.4), cyl = c(6, 
-6, 4, 6), disp = c(160, 160, 108, 258), hp = c(110, 110, 93, 
-110), drat = c(3.9, 3.9, 3.85, 3.08)), caption = NULL, theme = "table mytable", 
-    width = 0.666666666666667, notes = NULL, placement = "H")
-debug: idx <- grep("$tinytable_BOOTSTRAP_HEADER", template, fixed = TRUE)
-debug: if (!is.null(colnames(x))) {
-    header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-    header <- c("  <tr>", header, "  </tr>")
-    header <- paste(strrep(" ", 11), header)
-} else {
-    header <- NULL
-}
-debug: header <- sprintf("    <th scope=\"col\">%s</th>", colnames(x))
-debug: header <- c("  <tr>", header, "  </tr>")
-debug: header <- paste(strrep(" ", 11), header)
-debug: template <- c(template[1:(idx - 1)], header, template[(idx + 
-    1):length(template)])
-debug: makerow <- function(x) {
-    out <- c("  <tr>", sprintf("    <td>%s</td>", x), "  </tr>")
-    return(out)
-}
-debug: body <- apply(x, 1, makerow)
-debug: idx <- grep("$tinytable_BOOTSTRAP_BODY", template, fixed = TRUE)
-debug: template <- c(template[1:(idx - 1)], paste(strrep(" ", 13), body), 
-    template[(idx + 1):length(template)])
-debug: out <- paste(template, collapse = "\n")
-debug: class(out) <- c("tinytable", "knit_asis", class(out))
-debug: attr(out, "tinytable_meta") <- m
-debug: return(out)
-
+
css_rule <- "
+.mytable {
+  background: linear-gradient(45deg, #EA8D8D, #A890FE);
+  width: 600px;
+  border-collapse: collapse;
+  overflow: hidden;
+  box-shadow: 0 0 20px rgba(0,0,0,0.1);
+}
+
+.mytable th,
+.mytable td {
+  padding: 5px;
+  background-color: rgba(255,255,255,0.2);
+  color: #fff;
+}
+
+.mytable tbody tr:hover {
+  background-color: rgba(255,255,255,0.3);
+}
+
+.mytable tbody td:hover:before {
+  content: '';
+  position: absolute;
+  left: 0;
+  right: 0;
+  top: -9999px;
+  bottom: -9999px;
+  background-color: rgba(255,255,255,0.2);
+  z-index: -1;
+}
+"
+
+tt(x, theme = "table mytable", width = 2/3) |> 
+  style_tt(
+    j = 1:5,
+    align = "ccccc",
+    bootstrap_css_rule = css_rule)
@@ -6539,10 +4975,10 @@

CSS rules

- tinytable_zodr4colt2t4mazs5rog + tinytable_6kkm3iv60xuziv8omfbo