library(tinytable)
@@ -357,9 +360,9 @@ Tiny Tables
- tinytable_y8u50qp44b9nzxjjjp2t
+ tinytable_bg123fjsemjj3zc08n46
@@ -377,7 +380,7 @@ Tiny Tables
-
+
@@ -423,12 +426,12 @@ Tiny Tables
@@ -448,96 +451,20 @@ Tiny Tables
-
-Output formats
-tinytable
can produce tables in HTML, Word, Markdown, LaTeX, PDF, or PNG format. An appropriate output format for printing is automatically selected based on (1) whether the function is called interactively, (2) is called within RStudio, and (3) the output format of the Rmarkdown or Quarto document, if applicable. Alternatively, users can specify the print format in print()
or by setting a global option:
-
-tt(x) |> print("markdown")
-tt(x) |> print("html")
-tt(x) |> print("latex")
-
-options(tinytable_print_output = "markdown")
-
-With the save_tt()
function, users can also save tables directly to PNG (images), PDF or Word documents, and to any of the basic formats. All we need to do is supply a valid file name with the appropriate extension (ex: .png
, .html
, .pdf
, etc.):
-tt(x) |> save_tt("path/to/file.png")
-tt(x) |> save_tt("path/to/file.pdf")
-tt(x) |> save_tt("path/to/file.docx")
-tt(x) |> save_tt("path/to/file.html")
-tt(x) |> save_tt("path/to/file.tex")
-tt(x) |> save_tt("path/to/file.md")
-save_tt()
can also return a string with the table in it, for further processing in R
. In the first case, the table is printed to console with cat()
. In the second case, it returns as a single string as an R
object.
-
-tt(mtcars[1:10, 1:5]) |>
-group_tt(
- i = list(
- "Hello" = 3,
- "World" = 8),
- j = list(
- "Foo" = 2:3,
- "Bar" = 4:5)) |>
- print("markdown")
-
-
-+------+-------------+------------+
-| | Foo | Bar |
-+------+-----+-------+-----+------+
-| mpg | cyl | disp | hp | drat |
-+======+=====+=======+=====+======+
-| 21 | 6 | 160 | 110 | 3.9 |
-+------+-----+-------+-----+------+
-| 21 | 6 | 160 | 110 | 3.9 |
-+------+-----+-------+-----+------+
-| Hello |
-+------+-----+-------+-----+------+
-| 22.8 | 4 | 108 | 93 | 3.85 |
-+------+-----+-------+-----+------+
-| 21.4 | 6 | 258 | 110 | 3.08 |
-+------+-----+-------+-----+------+
-| 18.7 | 8 | 360 | 175 | 3.15 |
-+------+-----+-------+-----+------+
-| 18.1 | 6 | 225 | 105 | 2.76 |
-+------+-----+-------+-----+------+
-| 14.3 | 8 | 360 | 245 | 3.21 |
-+------+-----+-------+-----+------+
-| World |
-+------+-----+-------+-----+------+
-| 24.4 | 4 | 146.7 | 62 | 3.69 |
-+------+-----+-------+-----+------+
-| 22.8 | 4 | 140.8 | 95 | 3.92 |
-+------+-----+-------+-----+------+
-| 19.2 | 6 | 167.6 | 123 | 3.92 |
-+------+-----+-------+-----+------+
-
-
-
-tt(mtcars[1:10, 1:5]) |>
-group_tt(
- i = list(
- "Hello" = 3,
- "World" = 8),
- j = list(
- "Foo" = 2:3,
- "Bar" = 4:5)) |>
- save_tt("markdown")
-
-[1] "+------+-------------+------------+\n| | Foo | Bar |\n+------+-----+-------+-----+------+\n| mpg | cyl | disp | hp | drat |\n+======+=====+=======+=====+======+\n| 21 | 6 | 160 | 110 | 3.9 |\n+------+-----+-------+-----+------+\n| 21 | 6 | 160 | 110 | 3.9 |\n+------+-----+-------+-----+------+\n| Hello |\n+------+-----+-------+-----+------+\n| 22.8 | 4 | 108 | 93 | 3.85 |\n+------+-----+-------+-----+------+\n| 21.4 | 6 | 258 | 110 | 3.08 |\n+------+-----+-------+-----+------+\n| 18.7 | 8 | 360 | 175 | 3.15 |\n+------+-----+-------+-----+------+\n| 18.1 | 6 | 225 | 105 | 2.76 |\n+------+-----+-------+-----+------+\n| 14.3 | 8 | 360 | 245 | 3.21 |\n+------+-----+-------+-----+------+\n| World |\n+------+-----+-------+-----+------+\n| 24.4 | 4 | 146.7 | 62 | 3.69 |\n+------+-----+-------+-----+------+\n| 22.8 | 4 | 140.8 | 95 | 3.92 |\n+------+-----+-------+-----+------+\n| 19.2 | 6 | 167.6 | 123 | 3.92 |\n+------+-----+-------+-----+------+"
-
-
-
Themes
tinytable
offers a few basic themes out of the box: “default”, “striped”, “bootstrap”, “grid”, “void.” Those themes can be applied with the theme
argument of the tt()
function. As we will see below, it is easy to go much beyond those basic settings to customize your own tables. Here we only illustrate a few of the simplest settings:
-tt(x, theme = "striped")
+tt(x, theme = "striped")
- tinytable_hiyjjqe1qlv1wiigdg1z
+ tinytable_l8f2wk1bq373aeanv9om
@@ -555,7 +482,7 @@ Themes
-
+
@@ -601,12 +528,12 @@ Themes
@@ -642,16 +569,16 @@ Themes
-tt(x, theme = "grid")
+tt(x, theme = "grid")
- tinytable_t1fy4gtin8vn5egilf3d
+ tinytable_6rn9mctzlzwkhd1olybm
@@ -669,7 +596,7 @@ Themes
-
+
@@ -715,12 +642,12 @@ Themes
@@ -756,16 +683,16 @@ Themes
-tt(x, theme = "bootstrap")
+tt(x, theme = "bootstrap")
- tinytable_mgkzn9vb0arh7vr0uit7
+ tinytable_rmixurrdryvbj7shytwb
@@ -783,7 +710,7 @@ Themes
-
+
@@ -829,12 +756,12 @@ Themes
@@ -870,26 +797,20 @@ Themes
-
-Alignment
-To align columns, we use a single character, or a string where each letter represents a column:
+
+Width
+The width
arguments accepts a number between 0 and 1, indicating what proportion of the linewidth the table should cover:
-<- data.frame(
- dat a = c("a", "aa", "aaa"),
- b = c("b", "bb", "bbb"),
- c = c("c", "cc", "ccc"))
-
-tt(dat) |> style_tt(j = 1:3, align = "c")
+tt(x, width = 0.5)
- tinytable_ghu1fmkqwq43vsgsfqfy
+ tinytable_5cthvq6k97urueuavt0v
@@ -907,138 +828,58 @@ Alignment
-
+
- a
- b
- c
+ mpg
+ cyl
+ disp
+ hp
+ drat
- a
- b
- c
-
-
- aa
- bb
- cc
+ 21
+ 6
+ 160
+ 110
+ 3.9
- aaa
- bbb
- ccc
-
-
-
-
-
-
-
-
-
-
-
-tt(dat) |> style_tt(j = 1:3, align = "lcr")
-
-
-
-
-
-
- tinytable_ulhrdw03vg2d9ev18bg6
-
-
-
-
-
-
-
-
-
-
-
-
- a
- b
- c
-
-
-
-
-
- a
- b
- c
+ 21
+ 6
+ 160
+ 110
+ 3.9
- aa
- bb
- cc
+ 22.8
+ 4
+ 108
+ 93
+ 3.85
- aaa
- bbb
- ccc
+ 21.4
+ 6
+ 258
+ 110
+ 3.08
@@ -1068,28 +899,17 @@ Alignment
-
-
-Formatting (numbers, dates, strings, etc.)
-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()
:
-<- data.frame(
- dat 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)
+tt(x, width = 1)
- tinytable_otjlh1vsr4wc97pdv7eu
+ tinytable_zs61ffpauk2rf8zk8f86
@@ -1107,145 +927,58 @@ Form
-
+
- w
- x
- y
- z
+ mpg
+ cyl
+ disp
+ hp
+ drat
- 143002
- 1.43
- 1972-09-16
- True
-
-
- 201399
- 201.40
- 1970-11-16
- True
+ 21
+ 6
+ 160
+ 110
+ 3.9
- 100188
- 0.13
- 1970-06-04
- False
-
-
-
-
-
-
-
-
-
-
-
-
-We can get more fine-grained control over formatting by calling format_tt()
after tt()
, optionally by specifying the columns to format with j
:
-
-tt(dat) |>
-format_tt(
- j = 2:4,
- digits = 1,
- date = "%B %d %Y") |>
- format_tt(
- j = 1,
- digits = 2,
- num_mark_big = " ",
- num_mark_dec = ",",
- num_fmt = "decimal")
-
-
-
-
-
-
- tinytable_f34iqa8wsklp5lyzbbk3
-
-
-
-
-
-
-
-
-
-
-
-
- w
- x
- y
- z
-
-
-
-
-
- 143 002,21
- 1.4
- September 16 1972
- True
+ 21
+ 6
+ 160
+ 110
+ 3.9
- 201 399,18
- 201.4
- November 16 1970
- True
+ 22.8
+ 4
+ 108
+ 93
+ 3.85
- 100 188,39
- 0.1
- June 04 1970
- False
+ 21.4
+ 6
+ 258
+ 110
+ 3.08
@@ -1264,25 +998,38 @@ Form
-We can use a regular expression in j
to select columns, and the ?sprintf
function to format strings, numbers, and to do string interpolation (similar to the glue
package, but using Base R
):
+
+
Print a tinytable to console or viewer pane
+Description
+Print a tinytable to console or viewer pane
+Usage
+## S3 method for class 'tinytable'
+print(x, output = getOption("tinytable_print_output", default = NULL), ...)
+
+Arguments
+
+x
+ |
++A data frame or data table to be rendered as a table. + | +
+output
+ |
++One of "latex", "markdown", "html". If NULL, will guess the output based on the environment (interactive, RStudio, etc.). + | +
+…
+ |
++Other arguments are ignored. + | +
Value
+launch a browser window or cat() the table to console.
+ + +