diff --git a/man/format_tt.html b/man/format_tt.html index 935f392f..ac96e6ca 100644 --- a/man/format_tt.html +++ b/man/format_tt.html @@ -687,15 +687,15 @@

Examples

- +
@@ -756,16 +756,16 @@

Examples

- - + + - + - +
10 002 9 99910 00010 001
9 99910 000 9 999
10 00110 001 9 999
@@ -778,15 +778,15 @@

Examples

- +
@@ -868,15 +868,15 @@

Examples

-
+
@@ -968,15 +968,15 @@

Examples

-
+
@@ -1052,15 +1052,15 @@

Examples

-
+
@@ -1136,15 +1136,15 @@

Examples

-
+
@@ -1230,15 +1230,15 @@

Examples

-
+
diff --git a/man/group_tt.html b/man/group_tt.html index 58f953ad..0ccd9fa6 100644 --- a/man/group_tt.html +++ b/man/group_tt.html @@ -478,15 +478,15 @@

Examples

-
+
@@ -681,15 +681,15 @@

Examples

-
+
@@ -883,15 +883,15 @@

Examples

-
+
@@ -1087,15 +1087,15 @@

Examples

-
Hamburgers
+
diff --git a/man/rbind2-tinytable-tinytable-method.html b/man/rbind2-tinytable-tinytable-method.html index bcf91d23..a6449393 100644 --- a/man/rbind2-tinytable-tinytable-method.html +++ b/man/rbind2-tinytable-tinytable-method.html @@ -483,15 +483,15 @@

Examples

-
Foo
+
@@ -606,15 +606,15 @@

Examples

-
Combine two tiny tables.
+
@@ -730,15 +730,15 @@

Examples

-
Combine two tiny tables.
+
@@ -847,15 +847,15 @@

Examples

-
Combine two tiny tables.
+
diff --git a/man/theme_tt.html b/man/theme_tt.html index f34b8d97..ce74773f 100644 --- a/man/theme_tt.html +++ b/man/theme_tt.html @@ -517,15 +517,15 @@

Examples

-
Combine two tiny tables.
+
diff --git a/man/tt.html b/man/tt.html index 90c39b7f..f98bc459 100644 --- a/man/tt.html +++ b/man/tt.html @@ -608,15 +608,15 @@

Examples

-
+
@@ -720,15 +720,15 @@

Examples

-
+
@@ -952,15 +952,15 @@

Examples

-
+
diff --git a/search.json b/search.json index c98a79bb..414d4e26 100644 --- a/search.json +++ b/search.json @@ -219,7 +219,7 @@ "href": "vignettes/format.html", "title": "Formatting", "section": "", - "text": "library(tinytable)\noptions(tinytable_tt_digits = 3)\noptions(tinytable_theme_placement_latex_float = \"H\")\nx <- mtcars[1:4, 1:5]\n\n\n\nThe 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.\nIn a very simple case—such as printing 2 significant digits of all numeric variables—we can use the digits argument of tt():\n\ndat <- data.frame(\n w = c(143002.2092, 201399.181, 100188.3883),\n x = c(1.43402, 201.399, 0.134588),\n y = as.Date(sample(1:1000, 3), origin = \"1970-01-01\"),\n z = c(TRUE, TRUE, FALSE))\n\ntt(dat, digits = 2)\n\n\n\n \n\n \n \n \n \n \n \n w\n x\n y\n z\n \n \n \n \n \n 143002\n 1.43\n 1971-03-04\n True \n \n \n 201399\n 201.4 \n 1970-02-24\n True \n \n \n 100188\n 0.13\n 1970-12-02\n False\n \n \n \n \n\n\n\nWe can get more fine-grained control over formatting by calling format_tt() after tt(), optionally by specifying the columns to format with j:\n\ntt(dat) |> \n format_tt(\n j = 2:4,\n digits = 1,\n date = \"%B %d %Y\") |>\n format_tt(\n j = 1,\n digits = 2,\n num_mark_big = \" \",\n num_mark_dec = \",\",\n num_fmt = \"decimal\")\n\n\n\n \n\n \n \n \n \n \n \n w\n x\n y\n z\n \n \n \n \n \n 143 002,21\n 1.4\n March 04 1971\n True\n \n \n 201 399,18\n 201.4\n February 24 1970\n True\n \n \n 100 188,39\n 0.1\n December 02 1970\n False\n \n \n \n \n\n\n\nWe 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):\n\ndat <- data.frame(\n a = c(\"Burger\", \"Halloumi\", \"Tofu\", \"Beans\"),\n b = c(1.43202, 201.399, 0.146188, 0.0031),\n c = c(98938272783457, 7288839482, 29111727, 93945))\ntt(dat) |>\n format_tt(j = \"a\", sprintf = \"Food: %s\") |>\n format_tt(j = 2, digits = 1) |>\n format_tt(j = \"c\", digits = 2, num_suffix = TRUE)\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n c\n \n \n \n \n \n Food: Burger\n 1.432\n 99T\n \n \n Food: Halloumi\n 201.399\n 7.3B\n \n \n Food: Tofu\n 0.146\n 29M\n \n \n Food: Beans\n 0.003\n 94K\n \n \n \n \n\n\n\nFinally, if you like the format_tt() interface, you can use it directly with numbers, vectors, or data frames:\n\nformat_tt(pi, digits = 1)\n\n[1] \"3\"\n\nformat_tt(dat, digits = 1, num_suffix = TRUE)\n\n a b c\n1 Burger 1 99T\n2 Halloumi 201 7B\n3 Tofu 0.1 29M\n4 Beans 0.003 94K\n\n\n\n\n\nBy default, format_tt() formats numbers to ensure that the smallest value in a vector (column) has at least a certain number of significant digits. For example,\n\nk <- data.frame(x = c(0.000123456789, 12.4356789))\ntt(k, digits = 2)\n\n\n\n \n\n \n \n \n \n \n \n x\n \n \n \n \n \n 0.00012\n \n \n 12.43568\n \n \n \n \n\n\n\nWe can alter this behavior to ensure to round significant digits on a per-cell basis, using the num_fmt argument in format_tt():\n\ntt(k) |> format_tt(digits = 2, num_fmt = \"significant_cell\")\n\n\n\n \n\n \n \n \n \n \n \n x\n \n \n \n \n \n 0.00012\n \n \n 12\n \n \n \n \n\n\n\nThe numeric formatting options in format_tt() can also be controlled using global options:\n\noptions(\"tinytable_tt_digits\" = 2)\noptions(\"tinytable_format_num_fmt\" = \"significant_cell\")\ntt(k)\n\n\n\n \n\n \n \n \n \n \n \n x\n \n \n \n \n \n 0.00012\n \n \n 12 \n \n \n \n \n\n\n\n\n\n\nMissing values can be replaced by a custom string using the replace argument (default \"\"):\n\ntab <- data.frame(a = c(NA, 1, 2), b = c(3, NA, 5))\n\ntt(tab)\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n \n \n \n \n \n NA\n 3\n \n \n 1\n NA\n \n \n 2\n 5\n \n \n \n \n\n\ntt(tab) |> format_tt()\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n \n \n \n \n \n \n 3\n \n \n 1\n \n \n \n 2\n 5\n \n \n \n \n\n\ntt(tab) |> format_tt(replace = \"-\")\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n \n \n \n \n \n -\n 3\n \n \n 1\n -\n \n \n 2\n 5\n \n \n \n \n\n\n\nWe can also specify multiple value replacements at once using a named list of vectors:\n\ntmp <- data.frame(x = 1:5, y = c(pi, NA, NaN, -Inf, Inf))\ndict <- list(\"-\" = c(NA, NaN), \"-∞\" = -Inf, \"∞\" = Inf)\ntt(tmp) |> format_tt(replace = dict, digits = 2)\n\n\n\n \n\n \n \n \n \n \n \n x\n y\n \n \n \n \n \n 1\n 3.1\n \n \n 2\n -\n \n \n 3\n -\n \n \n 4\n -∞\n \n \n 5\n ∞\n \n \n \n \n\n\n\n\n\n\nLaTeX and HTML use special characters to indicate strings which should be interpreted rather than displayed as text. For example, including underscores or dollar signs in LaTeX can cause compilation errors in some documents. To display those special characters, we need to substitute or escape them with backslashes, depending on the output format. The escape argument of format_tt() can be used to do this automatically:\n\ndat <- data.frame(\n \"LaTeX\" = c(\"Dollars $\", \"Percent %\", \"Underscore _\"),\n \"HTML\" = c(\"<br>\", \"<sup>4</sup>\", \"<emph>blah</emph>\")\n)\n\ntt(dat) |> format_tt(escape = TRUE)\n\n\n\n \n\n \n \n \n \n \n \n LaTeX\n HTML\n \n \n \n \n \n Dollars $\n <br>\n \n \n Percent %\n <sup>4</sup>\n \n \n Underscore _\n <emph>blah</emph>\n \n \n \n \n\n\n\nWhen applied to a tt() table, format_tt() will determine the type of escaping to do automatically. When applied to a string or vector, we must specify the type of escaping to apply:\n\nformat_tt(\"_ Dollars $\", escape = \"latex\")\n\n[1] \"\\\\_ Dollars \\\\$\"\n\n\n\n\n\nMarkdown can be rendered in cells by using the markdown argument of the format_tt() function (note: this requires installing the markdown as an optional dependency).\n\ndat <- data.frame( markdown = c(\n \"This is _italic_ text.\",\n \"This sentence ends with a superscript.^2^\")\n)\n\ntt(dat) |>\n format_tt(j = 1, markdown = TRUE) |>\n style_tt(j = 1, align = \"c\")\n\n\n\n \n\n \n \n \n \n \n \n markdown\n \n \n \n \n \n This is italic text.\n \n \n This sentence ends with a superscript.2\n \n \n \n \n\n\n\nMarkdown syntax can be particularly useful when formatting URLs in a table:\n\ndat <- data.frame(\n `Package (link)` = c(\n \"[`marginaleffects`](https://www.marginaleffects.com/)\",\n \"[`modelsummary`](https://www.modelsummary.com/)\",\n \"[`tinytable`](https://vincentarelbundock.github.io/tinytable/)\",\n \"[`countrycode`](https://vincentarelbundock.github.io/countrycode/)\",\n \"[`WDI`](https://vincentarelbundock.github.io/WDI/)\",\n \"[`softbib`](https://vincentarelbundock.github.io/softbib/)\",\n \"[`tinysnapshot`](https://vincentarelbundock.github.io/tinysnapshot/)\",\n \"[`altdoc`](https://etiennebacher.github.io/altdoc/)\",\n \"[`tinyplot`](https://grantmcdermott.com/tinyplot/)\",\n \"[`parameters`](https://easystats.github.io/parameters/)\",\n \"[`insight`](https://easystats.github.io/insight/)\"\n ),\n Purpose = c(\n \"Interpreting statistical models\",\n \"Data and model summaries\",\n \"Draw beautiful tables easily\",\n \"Convert country codes and names\",\n \"Download data from the World Bank\",\n \"Software bibliographies in R\",\n \"Snapshots for unit tests using `tinytest`\",\n \"Create documentation website for R packages\",\n \"Extension of base R plot functions\",\n \"Extract from model objects\",\n \"Extract information from model objects\"\n ),\n check.names = FALSE\n)\n\ntt(dat) |> format_tt(j = 1, markdown = TRUE)\n\n\n\n \n\n \n \n Vincent sometimes contributes to these R packages.\n \n \n \n Package (link)\n Purpose\n \n \n \n \n \n marginaleffects\n Interpreting statistical models \n \n \n modelsummary\n Data and model summaries \n \n \n tinytable\n Draw beautiful tables easily \n \n \n countrycode\n Convert country codes and names \n \n \n WDI\n Download data from the World Bank \n \n \n softbib\n Software bibliographies in R \n \n \n tinysnapshot\n Snapshots for unit tests using `tinytest` \n \n \n altdoc\n Create documentation website for R packages\n \n \n tinyplot\n Extension of base R plot functions \n \n \n parameters\n Extract from model objects \n \n \n insight\n Extract information from model objects \n \n \n \n \n\n\n\n\n\n\nOn top of the built-in features of format_tt, a custom formatting function can be specified via the fn argument. The fn argument takes a function that accepts a single vector and returns a string (or something that coerces to a string like a number).\n\ntt(x) |> \n format_tt(j = \"mpg\", fn = function(x) paste0(x, \" mpg\")) |>\n format_tt(j = \"drat\", fn = \\(x) signif(x, 2))\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 mpg\n 6\n 160\n 110\n 3.9\n \n \n 21 mpg\n 6\n 160\n 110\n 3.9\n \n \n 22.8 mpg\n 4\n 108\n 93\n 3.8\n \n \n 21.4 mpg\n 6\n 258\n 110\n 3.1\n \n \n \n \n\n\n\nFor example, the scales package which is used internally by ggplot2 provides a bunch of useful tools for formatting (e.g. dates, numbers, percents, logs, currencies, etc.). The label_*() functions can be passed to the fn argument.\nNote that we call format_tt(escape = TRUE) at the end of the pipeline because the column names and cells include characters that need to be escaped in LaTeX: _, %, and $. This last call is superfluous in HTML.\n\nthumbdrives <- data.frame(\n date_lookup = as.Date(c(\"2024-01-15\", \"2024-01-18\", \"2024-01-14\", \"2024-01-16\")),\n price = c(18.49, 19.99, 24.99, 24.99),\n price_rank = c(1, 2, 3, 3),\n memory = c(16e9, 12e9, 10e9, 8e9),\n speed_benchmark = c(0.6, 0.73, 0.82, 0.99)\n)\n\ntt(thumbdrives) |>\n format_tt(j = 1, fn = scales::label_date(\"%e %b\", locale = \"fr\")) |>\n format_tt(j = 2, fn = scales::label_currency()) |>\n format_tt(j = 3, fn = scales::label_ordinal()) |> \n format_tt(j = 4, fn = scales::label_bytes()) |> \n format_tt(j = 5, fn = scales::label_percent()) |>\n format_tt(escape = TRUE)\n\n\n\n \n\n \n \n \n \n \n \n date_lookup\n price\n price_rank\n memory\n speed_benchmark\n \n \n \n \n \n 2024-01-15\n $18.49\n 1st\n 16 GB\n 60%\n \n \n 2024-01-18\n $19.99\n 2nd\n 12 GB\n 73%\n \n \n 2024-01-14\n $24.99\n 3rd\n 10 GB\n 82%\n \n \n 2024-01-16\n $24.99\n 3rd\n 8 GB\n 99%\n \n \n \n \n\n\n\n\n\n\nQuarto automatically applies some data processing to the content of the tables it renders. By default, tinytable disables this processing, because it can enter in conflict with styling and formatting features of the package.\nTo enable Quarto data processing, we can use the quarto argument of the format_tt() function. This argument allows users to mark certain cells explicitly for processing by Quarto, by wrapping them in a special “span” called “data-qmd”, supported by Quarto:\n\nk <- data.frame(Thing = \"qwerty\", Citation = \"@Lovelace1842\")\n\ntt(k) |> format_tt(quarto = TRUE)\n\n\n\n \n\n \n \n \n\n\n\nThing\nCitation\n\n\n\n\nqwerty\nLovelace (1842)\n\n\n\n\n \n\n\n\nSome users may want to apply Quarto data processing to all tables. This can be done with themes:\n\ntheme_quarto <- function(x) format_tt(x, quarto = TRUE)\noptions(tinytable_tt_theme = theme_quarto)\n\ntt(k)\n\n\n\n \n\n \n \n \n\n\n\nThing\nCitation\n\n\n\n\nqwerty\nLovelace (1842)\n\n\n\n\n \n\n\n\nBack to normal:\n\noptions(tinytable_tt_theme = NULL)\n\nAlternatively, users can set a global option to process all tables in Quarto, but they will then have to mark each cell with special content using format_tt(quarto):\n\noptions(tinytable_quarto_disable_processing = FALSE)\n\ntt(x)\n\n\n\n \n\n \n \n \n\n\n\nmpg\ncyl\ndisp\nhp\ndrat\n\n\n\n\n21.0\n6\n160\n110\n3.90\n\n\n21.0\n6\n160\n110\n3.90\n\n\n22.8\n4\n108\n93\n3.85\n\n\n21.4\n6\n258\n110\n3.08\n\n\n\n\n \n\n\n\nNotice that Quarto is now processing the table, so we lose the default tinytable theme and get the default striped Quarto look.\nBack to normal:\n\noptions(tinytable_quarto_disable_processing = TRUE)", + "text": "library(tinytable)\noptions(tinytable_tt_digits = 3)\noptions(tinytable_theme_placement_latex_float = \"H\")\nx <- mtcars[1:4, 1:5]\n\n\n\nThe 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.\nIn a very simple case—such as printing 2 significant digits of all numeric variables—we can use the digits argument of tt():\n\ndat <- data.frame(\n w = c(143002.2092, 201399.181, 100188.3883),\n x = c(1.43402, 201.399, 0.134588),\n y = as.Date(sample(1:1000, 3), origin = \"1970-01-01\"),\n z = c(TRUE, TRUE, FALSE))\n\ntt(dat, digits = 2)\n\n\n\n \n\n \n \n \n \n \n \n w\n x\n y\n z\n \n \n \n \n \n 143002\n 1.43\n 1971-02-06\n True \n \n \n 201399\n 201.4 \n 1970-04-30\n True \n \n \n 100188\n 0.13\n 1972-02-21\n False\n \n \n \n \n\n\n\nWe can get more fine-grained control over formatting by calling format_tt() after tt(), optionally by specifying the columns to format with j:\n\ntt(dat) |> \n format_tt(\n j = 2:4,\n digits = 1,\n date = \"%B %d %Y\") |>\n format_tt(\n j = 1,\n digits = 2,\n num_mark_big = \" \",\n num_mark_dec = \",\",\n num_fmt = \"decimal\")\n\n\n\n \n\n \n \n \n \n \n \n w\n x\n y\n z\n \n \n \n \n \n 143 002,21\n 1.4\n February 06 1971\n True\n \n \n 201 399,18\n 201.4\n April 30 1970\n True\n \n \n 100 188,39\n 0.1\n February 21 1972\n False\n \n \n \n \n\n\n\nWe 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):\n\ndat <- data.frame(\n a = c(\"Burger\", \"Halloumi\", \"Tofu\", \"Beans\"),\n b = c(1.43202, 201.399, 0.146188, 0.0031),\n c = c(98938272783457, 7288839482, 29111727, 93945))\ntt(dat) |>\n format_tt(j = \"a\", sprintf = \"Food: %s\") |>\n format_tt(j = 2, digits = 1) |>\n format_tt(j = \"c\", digits = 2, num_suffix = TRUE)\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n c\n \n \n \n \n \n Food: Burger\n 1.432\n 99T\n \n \n Food: Halloumi\n 201.399\n 7.3B\n \n \n Food: Tofu\n 0.146\n 29M\n \n \n Food: Beans\n 0.003\n 94K\n \n \n \n \n\n\n\nFinally, if you like the format_tt() interface, you can use it directly with numbers, vectors, or data frames:\n\nformat_tt(pi, digits = 1)\n\n[1] \"3\"\n\nformat_tt(dat, digits = 1, num_suffix = TRUE)\n\n a b c\n1 Burger 1 99T\n2 Halloumi 201 7B\n3 Tofu 0.1 29M\n4 Beans 0.003 94K\n\n\n\n\n\nBy default, format_tt() formats numbers to ensure that the smallest value in a vector (column) has at least a certain number of significant digits. For example,\n\nk <- data.frame(x = c(0.000123456789, 12.4356789))\ntt(k, digits = 2)\n\n\n\n \n\n \n \n \n \n \n \n x\n \n \n \n \n \n 0.00012\n \n \n 12.43568\n \n \n \n \n\n\n\nWe can alter this behavior to ensure to round significant digits on a per-cell basis, using the num_fmt argument in format_tt():\n\ntt(k) |> format_tt(digits = 2, num_fmt = \"significant_cell\")\n\n\n\n \n\n \n \n \n \n \n \n x\n \n \n \n \n \n 0.00012\n \n \n 12\n \n \n \n \n\n\n\nThe numeric formatting options in format_tt() can also be controlled using global options:\n\noptions(\"tinytable_tt_digits\" = 2)\noptions(\"tinytable_format_num_fmt\" = \"significant_cell\")\ntt(k)\n\n\n\n \n\n \n \n \n \n \n \n x\n \n \n \n \n \n 0.00012\n \n \n 12 \n \n \n \n \n\n\n\n\n\n\nMissing values can be replaced by a custom string using the replace argument (default \"\"):\n\ntab <- data.frame(a = c(NA, 1, 2), b = c(3, NA, 5))\n\ntt(tab)\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n \n \n \n \n \n NA\n 3\n \n \n 1\n NA\n \n \n 2\n 5\n \n \n \n \n\n\ntt(tab) |> format_tt()\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n \n \n \n \n \n \n 3\n \n \n 1\n \n \n \n 2\n 5\n \n \n \n \n\n\ntt(tab) |> format_tt(replace = \"-\")\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n \n \n \n \n \n -\n 3\n \n \n 1\n -\n \n \n 2\n 5\n \n \n \n \n\n\n\nWe can also specify multiple value replacements at once using a named list of vectors:\n\ntmp <- data.frame(x = 1:5, y = c(pi, NA, NaN, -Inf, Inf))\ndict <- list(\"-\" = c(NA, NaN), \"-∞\" = -Inf, \"∞\" = Inf)\ntt(tmp) |> format_tt(replace = dict, digits = 2)\n\n\n\n \n\n \n \n \n \n \n \n x\n y\n \n \n \n \n \n 1\n 3.1\n \n \n 2\n -\n \n \n 3\n -\n \n \n 4\n -∞\n \n \n 5\n ∞\n \n \n \n \n\n\n\n\n\n\nLaTeX and HTML use special characters to indicate strings which should be interpreted rather than displayed as text. For example, including underscores or dollar signs in LaTeX can cause compilation errors in some documents. To display those special characters, we need to substitute or escape them with backslashes, depending on the output format. The escape argument of format_tt() can be used to do this automatically:\n\ndat <- data.frame(\n \"LaTeX\" = c(\"Dollars $\", \"Percent %\", \"Underscore _\"),\n \"HTML\" = c(\"<br>\", \"<sup>4</sup>\", \"<emph>blah</emph>\")\n)\n\ntt(dat) |> format_tt(escape = TRUE)\n\n\n\n \n\n \n \n \n \n \n \n LaTeX\n HTML\n \n \n \n \n \n Dollars $\n <br>\n \n \n Percent %\n <sup>4</sup>\n \n \n Underscore _\n <emph>blah</emph>\n \n \n \n \n\n\n\nWhen applied to a tt() table, format_tt() will determine the type of escaping to do automatically. When applied to a string or vector, we must specify the type of escaping to apply:\n\nformat_tt(\"_ Dollars $\", escape = \"latex\")\n\n[1] \"\\\\_ Dollars \\\\$\"\n\n\n\n\n\nMarkdown can be rendered in cells by using the markdown argument of the format_tt() function (note: this requires installing the markdown as an optional dependency).\n\ndat <- data.frame( markdown = c(\n \"This is _italic_ text.\",\n \"This sentence ends with a superscript.^2^\")\n)\n\ntt(dat) |>\n format_tt(j = 1, markdown = TRUE) |>\n style_tt(j = 1, align = \"c\")\n\n\n\n \n\n \n \n \n \n \n \n markdown\n \n \n \n \n \n This is italic text.\n \n \n This sentence ends with a superscript.2\n \n \n \n \n\n\n\nMarkdown syntax can be particularly useful when formatting URLs in a table:\n\ndat <- data.frame(\n `Package (link)` = c(\n \"[`marginaleffects`](https://www.marginaleffects.com/)\",\n \"[`modelsummary`](https://www.modelsummary.com/)\",\n \"[`tinytable`](https://vincentarelbundock.github.io/tinytable/)\",\n \"[`countrycode`](https://vincentarelbundock.github.io/countrycode/)\",\n \"[`WDI`](https://vincentarelbundock.github.io/WDI/)\",\n \"[`softbib`](https://vincentarelbundock.github.io/softbib/)\",\n \"[`tinysnapshot`](https://vincentarelbundock.github.io/tinysnapshot/)\",\n \"[`altdoc`](https://etiennebacher.github.io/altdoc/)\",\n \"[`tinyplot`](https://grantmcdermott.com/tinyplot/)\",\n \"[`parameters`](https://easystats.github.io/parameters/)\",\n \"[`insight`](https://easystats.github.io/insight/)\"\n ),\n Purpose = c(\n \"Interpreting statistical models\",\n \"Data and model summaries\",\n \"Draw beautiful tables easily\",\n \"Convert country codes and names\",\n \"Download data from the World Bank\",\n \"Software bibliographies in R\",\n \"Snapshots for unit tests using `tinytest`\",\n \"Create documentation website for R packages\",\n \"Extension of base R plot functions\",\n \"Extract from model objects\",\n \"Extract information from model objects\"\n ),\n check.names = FALSE\n)\n\ntt(dat) |> format_tt(j = 1, markdown = TRUE)\n\n\n\n \n\n \n \n Vincent sometimes contributes to these R packages.\n \n \n \n Package (link)\n Purpose\n \n \n \n \n \n marginaleffects\n Interpreting statistical models \n \n \n modelsummary\n Data and model summaries \n \n \n tinytable\n Draw beautiful tables easily \n \n \n countrycode\n Convert country codes and names \n \n \n WDI\n Download data from the World Bank \n \n \n softbib\n Software bibliographies in R \n \n \n tinysnapshot\n Snapshots for unit tests using `tinytest` \n \n \n altdoc\n Create documentation website for R packages\n \n \n tinyplot\n Extension of base R plot functions \n \n \n parameters\n Extract from model objects \n \n \n insight\n Extract information from model objects \n \n \n \n \n\n\n\n\n\n\nOn top of the built-in features of format_tt, a custom formatting function can be specified via the fn argument. The fn argument takes a function that accepts a single vector and returns a string (or something that coerces to a string like a number).\n\ntt(x) |> \n format_tt(j = \"mpg\", fn = function(x) paste0(x, \" mpg\")) |>\n format_tt(j = \"drat\", fn = \\(x) signif(x, 2))\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 mpg\n 6\n 160\n 110\n 3.9\n \n \n 21 mpg\n 6\n 160\n 110\n 3.9\n \n \n 22.8 mpg\n 4\n 108\n 93\n 3.8\n \n \n 21.4 mpg\n 6\n 258\n 110\n 3.1\n \n \n \n \n\n\n\nFor example, the scales package which is used internally by ggplot2 provides a bunch of useful tools for formatting (e.g. dates, numbers, percents, logs, currencies, etc.). The label_*() functions can be passed to the fn argument.\nNote that we call format_tt(escape = TRUE) at the end of the pipeline because the column names and cells include characters that need to be escaped in LaTeX: _, %, and $. This last call is superfluous in HTML.\n\nthumbdrives <- data.frame(\n date_lookup = as.Date(c(\"2024-01-15\", \"2024-01-18\", \"2024-01-14\", \"2024-01-16\")),\n price = c(18.49, 19.99, 24.99, 24.99),\n price_rank = c(1, 2, 3, 3),\n memory = c(16e9, 12e9, 10e9, 8e9),\n speed_benchmark = c(0.6, 0.73, 0.82, 0.99)\n)\n\ntt(thumbdrives) |>\n format_tt(j = 1, fn = scales::label_date(\"%e %b\", locale = \"fr\")) |>\n format_tt(j = 2, fn = scales::label_currency()) |>\n format_tt(j = 3, fn = scales::label_ordinal()) |> \n format_tt(j = 4, fn = scales::label_bytes()) |> \n format_tt(j = 5, fn = scales::label_percent()) |>\n format_tt(escape = TRUE)\n\n\n\n \n\n \n \n \n \n \n \n date_lookup\n price\n price_rank\n memory\n speed_benchmark\n \n \n \n \n \n 2024-01-15\n $18.49\n 1st\n 16 GB\n 60%\n \n \n 2024-01-18\n $19.99\n 2nd\n 12 GB\n 73%\n \n \n 2024-01-14\n $24.99\n 3rd\n 10 GB\n 82%\n \n \n 2024-01-16\n $24.99\n 3rd\n 8 GB\n 99%\n \n \n \n \n\n\n\n\n\n\nQuarto automatically applies some data processing to the content of the tables it renders. By default, tinytable disables this processing, because it can enter in conflict with styling and formatting features of the package.\nTo enable Quarto data processing, we can use the quarto argument of the format_tt() function. This argument allows users to mark certain cells explicitly for processing by Quarto, by wrapping them in a special “span” called “data-qmd”, supported by Quarto:\n\nk <- data.frame(Thing = \"qwerty\", Citation = \"@Lovelace1842\")\n\ntt(k) |> format_tt(quarto = TRUE)\n\n\n\n \n\n \n \n \n\n\n\nThing\nCitation\n\n\n\n\nqwerty\nLovelace (1842)\n\n\n\n\n \n\n\n\nSome users may want to apply Quarto data processing to all tables. This can be done with themes:\n\ntheme_quarto <- function(x) format_tt(x, quarto = TRUE)\noptions(tinytable_tt_theme = theme_quarto)\n\ntt(k)\n\n\n\n \n\n \n \n \n\n\n\nThing\nCitation\n\n\n\n\nqwerty\nLovelace (1842)\n\n\n\n\n \n\n\n\nBack to normal:\n\noptions(tinytable_tt_theme = NULL)\n\nAlternatively, users can set a global option to process all tables in Quarto, but they will then have to mark each cell with special content using format_tt(quarto):\n\noptions(tinytable_quarto_disable_processing = FALSE)\n\ntt(x)\n\n\n\n \n\n \n \n \n\n\n\nmpg\ncyl\ndisp\nhp\ndrat\n\n\n\n\n21.0\n6\n160\n110\n3.90\n\n\n21.0\n6\n160\n110\n3.90\n\n\n22.8\n4\n108\n93\n3.85\n\n\n21.4\n6\n258\n110\n3.08\n\n\n\n\n \n\n\n\nNotice that Quarto is now processing the table, so we lose the default tinytable theme and get the default striped Quarto look.\nBack to normal:\n\noptions(tinytable_quarto_disable_processing = TRUE)", "crumbs": [ "Tutorial (PDF)", "Tutorial", @@ -231,7 +231,7 @@ "href": "vignettes/format.html#numbers-dates-strings-etc.", "title": "Formatting", "section": "", - "text": "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.\nIn a very simple case—such as printing 2 significant digits of all numeric variables—we can use the digits argument of tt():\n\ndat <- data.frame(\n w = c(143002.2092, 201399.181, 100188.3883),\n x = c(1.43402, 201.399, 0.134588),\n y = as.Date(sample(1:1000, 3), origin = \"1970-01-01\"),\n z = c(TRUE, TRUE, FALSE))\n\ntt(dat, digits = 2)\n\n\n\n \n\n \n \n \n \n \n \n w\n x\n y\n z\n \n \n \n \n \n 143002\n 1.43\n 1971-03-04\n True \n \n \n 201399\n 201.4 \n 1970-02-24\n True \n \n \n 100188\n 0.13\n 1970-12-02\n False\n \n \n \n \n\n\n\nWe can get more fine-grained control over formatting by calling format_tt() after tt(), optionally by specifying the columns to format with j:\n\ntt(dat) |> \n format_tt(\n j = 2:4,\n digits = 1,\n date = \"%B %d %Y\") |>\n format_tt(\n j = 1,\n digits = 2,\n num_mark_big = \" \",\n num_mark_dec = \",\",\n num_fmt = \"decimal\")\n\n\n\n \n\n \n \n \n \n \n \n w\n x\n y\n z\n \n \n \n \n \n 143 002,21\n 1.4\n March 04 1971\n True\n \n \n 201 399,18\n 201.4\n February 24 1970\n True\n \n \n 100 188,39\n 0.1\n December 02 1970\n False\n \n \n \n \n\n\n\nWe 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):\n\ndat <- data.frame(\n a = c(\"Burger\", \"Halloumi\", \"Tofu\", \"Beans\"),\n b = c(1.43202, 201.399, 0.146188, 0.0031),\n c = c(98938272783457, 7288839482, 29111727, 93945))\ntt(dat) |>\n format_tt(j = \"a\", sprintf = \"Food: %s\") |>\n format_tt(j = 2, digits = 1) |>\n format_tt(j = \"c\", digits = 2, num_suffix = TRUE)\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n c\n \n \n \n \n \n Food: Burger\n 1.432\n 99T\n \n \n Food: Halloumi\n 201.399\n 7.3B\n \n \n Food: Tofu\n 0.146\n 29M\n \n \n Food: Beans\n 0.003\n 94K\n \n \n \n \n\n\n\nFinally, if you like the format_tt() interface, you can use it directly with numbers, vectors, or data frames:\n\nformat_tt(pi, digits = 1)\n\n[1] \"3\"\n\nformat_tt(dat, digits = 1, num_suffix = TRUE)\n\n a b c\n1 Burger 1 99T\n2 Halloumi 201 7B\n3 Tofu 0.1 29M\n4 Beans 0.003 94K", + "text": "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.\nIn a very simple case—such as printing 2 significant digits of all numeric variables—we can use the digits argument of tt():\n\ndat <- data.frame(\n w = c(143002.2092, 201399.181, 100188.3883),\n x = c(1.43402, 201.399, 0.134588),\n y = as.Date(sample(1:1000, 3), origin = \"1970-01-01\"),\n z = c(TRUE, TRUE, FALSE))\n\ntt(dat, digits = 2)\n\n\n\n \n\n \n \n \n \n \n \n w\n x\n y\n z\n \n \n \n \n \n 143002\n 1.43\n 1971-02-06\n True \n \n \n 201399\n 201.4 \n 1970-04-30\n True \n \n \n 100188\n 0.13\n 1972-02-21\n False\n \n \n \n \n\n\n\nWe can get more fine-grained control over formatting by calling format_tt() after tt(), optionally by specifying the columns to format with j:\n\ntt(dat) |> \n format_tt(\n j = 2:4,\n digits = 1,\n date = \"%B %d %Y\") |>\n format_tt(\n j = 1,\n digits = 2,\n num_mark_big = \" \",\n num_mark_dec = \",\",\n num_fmt = \"decimal\")\n\n\n\n \n\n \n \n \n \n \n \n w\n x\n y\n z\n \n \n \n \n \n 143 002,21\n 1.4\n February 06 1971\n True\n \n \n 201 399,18\n 201.4\n April 30 1970\n True\n \n \n 100 188,39\n 0.1\n February 21 1972\n False\n \n \n \n \n\n\n\nWe 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):\n\ndat <- data.frame(\n a = c(\"Burger\", \"Halloumi\", \"Tofu\", \"Beans\"),\n b = c(1.43202, 201.399, 0.146188, 0.0031),\n c = c(98938272783457, 7288839482, 29111727, 93945))\ntt(dat) |>\n format_tt(j = \"a\", sprintf = \"Food: %s\") |>\n format_tt(j = 2, digits = 1) |>\n format_tt(j = \"c\", digits = 2, num_suffix = TRUE)\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n c\n \n \n \n \n \n Food: Burger\n 1.432\n 99T\n \n \n Food: Halloumi\n 201.399\n 7.3B\n \n \n Food: Tofu\n 0.146\n 29M\n \n \n Food: Beans\n 0.003\n 94K\n \n \n \n \n\n\n\nFinally, if you like the format_tt() interface, you can use it directly with numbers, vectors, or data frames:\n\nformat_tt(pi, digits = 1)\n\n[1] \"3\"\n\nformat_tt(dat, digits = 1, num_suffix = TRUE)\n\n a b c\n1 Burger 1 99T\n2 Halloumi 201 7B\n3 Tofu 0.1 29M\n4 Beans 0.003 94K", "crumbs": [ "Tutorial (PDF)", "Tutorial", @@ -467,7 +467,7 @@ "href": "man/format_tt.html", "title": "tinytable", "section": "", - "text": "This function formats the columns of a data frame based on the column type (logical, date, numeric). It allows various formatting options like significant digits, decimal points, and scientific notation. It also includes custom formatting for date and boolean values. If this function is applied several times to the same cell, the last transformation is retained and the previous calls are ignored, except for the escape argument which can be applied to previously transformed data.\n\n\n\nformat_tt(\n x,\n i = NULL,\n j = NULL,\n digits = getOption(\"tinytable_format_digits\", default = NULL),\n num_fmt = getOption(\"tinytable_format_num_fmt\", default = \"significant\"),\n num_zero = getOption(\"tinytable_format_num_zero\", default = FALSE),\n num_suffix = getOption(\"tinytable_format_num_suffix\", default = FALSE),\n num_mark_big = getOption(\"tinytable_format_num_mark_big\", default = \"\"),\n num_mark_dec = getOption(\"tinytable_format_num_mark_dec\", default = getOption(\"OutDec\",\n default = \".\")),\n date = getOption(\"tinytable_format_date\", default = \"%Y-%m-%d\"),\n bool = getOption(\"tinytable_format_bool\", default = function(column)\n tools::toTitleCase(tolower(column))),\n other = getOption(\"tinytable_format_other\", default = as.character),\n replace = getOption(\"tinytable_format_replace\", default = TRUE),\n escape = getOption(\"tinytable_format_escape\", default = FALSE),\n markdown = getOption(\"tinytable_format_markdown\", default = FALSE),\n quarto = getOption(\"tinytable_format_quarto\", default = FALSE),\n fn = getOption(\"tinytable_format_fn\", default = NULL),\n sprintf = getOption(\"tinytable_format_sprintf\", default = NULL),\n ...\n)\n\n\n\n\n\n\n\nx\n\n\nA data frame or a vector to be formatted.\n\n\n\n\ni\n\n\nRow indices where the formatting should be applied.\n\n\n\n\nj\n\n\nColumn indices where the styling should be applied. Can be:\n\n\nInteger vectors indicating column positions.\n\n\nCharacter vector indicating column names.\n\n\nA single string specifying a Perl-style regular expression used to match column names.\n\n\n\n\n\n\ndigits\n\n\nNumber of significant digits or decimal places.\n\n\n\n\nnum_fmt\n\n\nThe format for numeric values; one of ‘significant’, ‘significant_cell’, ‘decimal’, or ‘scientific’.\n\n\n\n\nnum_zero\n\n\nLogical; if TRUE, trailing zeros are kept in \"decimal\" format (but not in \"significant\" format).\n\n\n\n\nnum_suffix\n\n\nLogical; if TRUE display short numbers with digits significant digits and K (thousands), M (millions), B (billions), or T (trillions) suffixes.\n\n\n\n\nnum_mark_big\n\n\nCharacter to use as a thousands separator.\n\n\n\n\nnum_mark_dec\n\n\nDecimal mark character. Default is the global option ‘OutDec’.\n\n\n\n\ndate\n\n\nA string passed to the format() function, such as \"%Y-%m-%d\". See the \"Details\" section in ?strptime\n\n\n\n\nbool\n\n\nA function to format logical columns. Defaults to title case.\n\n\n\n\nother\n\n\nA function to format columns of other types. Defaults to as.character().\n\n\n\n\nreplace\n\n\nLogical, String or Named list of vectors\n\n\nTRUE: Replace NA by an empty string.\n\n\nFALSE: Print NA as the string \"NA\".\n\n\nString: Replace NA entries by the user-supplied string.\n\n\nNamed list: Replace matching elements of the vectors in the list by theirs names. Example:\n\n\nlist(“-” = c(NA, NaN), “Tiny” = -Inf, “Massive” = Inf)\n\n\n\n\n\n\n\n\nescape\n\n\nLogical or \"latex\" or \"html\". If TRUE, escape special characters to display them as text in the format of the output of a tt() table.\n\n\nIf i and j are both NULL, escape all cells, column names, caption, notes, and spanning labels created by group_tt().\n\n\n\n\n\n\nmarkdown\n\n\nLogical; if TRUE, render markdown syntax in cells. Ex: italicized text is properly italicized in HTML and LaTeX.\n\n\n\n\nquarto\n\n\nLogical. Enable Quarto data processing and wrap cell content in a data-qmd span (HTML) or macro (LaTeX). See warnings in the Global Options section below.\n\n\n\n\nfn\n\n\nFunction for custom formatting. Accepts a vector and returns a character vector of the same length.\n\n\n\n\nsprintf\n\n\nString passed to the ?sprintf function to format numbers or interpolate strings with a user-defined pattern (similar to the glue package, but using Base R).\n\n\n\n\n…\n\n\nAdditional arguments are ignored.\n\n\n\n\n\n\nA data frame with formatted columns.\n\n\n\n\nWhen the x data frame includes row names, tinytable can bind them to the first column (without an empty string string as column name). This global option triggers this behavior:\n\noptions(tinytable_tt_rownames = TRUE)\n\nx <- mtcars[1:3, 1:3]\ntt(x)\n\noptions(tinytable_tt_rownames = FALSE)\n\n\n\nThe format_tt(quarto=TRUE) argument activates Quarto data processing for specific cells. This funcationality comes with a few warnings:\n\n\nCurrently, Quarto provides a LaTeX macro, but it does not appear to do anything with it. References and markdown codes may not be processed as expected in LaTeX.\n\n\nQuarto data processing can enter in conflict with tinytable styling or formatting options. See below for how to disable it.\n\n\noptions(tinytable_quarto_disable_processing = TRUE)\nDisable Quarto processing of cell content. Setting this global option to FALSE may lead to conflicts with some tinytable features, but it also allows use of markdown and Quarto-specific code in table cells, such as cross-references.\n\nx <- data.frame(Math = \"x^2^\", Citation = \"@Lovelace1842\")\nfn <- function(z) sprintf(\"<span data-qmd='%s'></span>\", z)\ntt(x) |> format_tt(i = 1, fn = fn)\n\n\nSee this link for more details: https://quarto.org/docs/authoring/tables.html#disabling-quarto-table-processing\n\n\n\nEXPERIMENTAL options(tinytable_html_mathjax = TRUE) inserts MathJax scripts in the HTML document. Warning: This may conflict with other elements of the page if MathJax is otherwise loaded.\n\n\n\n\n\noptions(tinytable_save_pdf_clean = TRUE) deletes temporary and log files.\n\n\noptions(tinytable_save_pdf_engine = “xelatex”): \"xelatex\", \"pdflatex\", \"lualatex\"\n\n\n\n\n\n\nlibrary(\"tinytable\")\n\ndat <- data.frame(\n a = rnorm(3, mean = 10000),\n b = rnorm(3, 10000))\ntab <- tt(dat)\nformat_tt(tab,\n digits = 2,\n num_mark_dec = \",\",\n num_mark_big = \" \")\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n \n \n \n \n \n 10 002\n 9 999\n \n \n 9 999\n 10 000\n \n \n 10 001\n 10 001\n \n \n \n \n\n\nk <- tt(data.frame(x = c(0.000123456789, 12.4356789)))\nformat_tt(k, digits = 2, num_fmt = \"significant_cell\")\n\n\n\n \n\n \n \n \n \n \n \n x\n \n \n \n \n \n 0.00012\n \n \n 12\n \n \n \n \n\n\ndat <- data.frame(\n a = c(\"Burger\", \"Halloumi\", \"Tofu\", \"Beans\"),\n b = c(1.43202, 201.399, 0.146188, 0.0031),\n c = c(98938272783457, 7288839482, 29111727, 93945))\ntt(dat) |>\n format_tt(j = \"a\", sprintf = \"Food: %s\") |>\n format_tt(j = 2, digits = 1, num_fmt = \"decimal\", num_zero = TRUE) |>\n format_tt(j = \"c\", digits = 2, num_suffix = TRUE)\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n c\n \n \n \n \n \n Food: Burger\n 1.4\n 99T\n \n \n Food: Halloumi\n 201.4\n 7.3B\n \n \n Food: Tofu\n 0.1\n 29M\n \n \n Food: Beans\n 0.0\n 94K\n \n \n \n \n\n\ny <- tt(data.frame(x = c(123456789.678, 12435.6789)))\nformat_tt(y, digits=3, num_mark_big=\" \")\n\n\n\n \n\n \n \n \n \n \n \n x\n \n \n \n \n \n 123 456 790\n \n \n 12 436\n \n \n \n \n\n\nx <- tt(data.frame(Text = c(\"_italicized text_\", \"__bold text__\")))\nformat_tt(x, markdown=TRUE)\n\n\n\n \n\n \n \n \n \n \n \n Text\n \n \n \n \n \n italicized text\n \n \n bold text\n \n \n \n \n\n\ntab <- data.frame(a = c(NA, 1, 2), b = c(3, NA, 5))\ntt(tab) |> format_tt(replace = \"-\")\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n \n \n \n \n \n -\n 3\n \n \n 1\n -\n \n \n 2\n 5\n \n \n \n \n\n\ndat <- data.frame(\n \"LaTeX\" = c(\"Dollars $\", \"Percent %\", \"Underscore _\"),\n \"HTML\" = c(\"<br>\", \"<sup>4</sup>\", \"<emph>blah</emph>\")\n)\ntt(dat) |> format_tt(escape = TRUE) \n\n\n\n \n\n \n \n \n \n \n \n LaTeX\n HTML\n \n \n \n \n \n Dollars $\n <br>\n \n \n Percent %\n <sup>4</sup>\n \n \n Underscore _\n <emph>blah</emph>", + "text": "This function formats the columns of a data frame based on the column type (logical, date, numeric). It allows various formatting options like significant digits, decimal points, and scientific notation. It also includes custom formatting for date and boolean values. If this function is applied several times to the same cell, the last transformation is retained and the previous calls are ignored, except for the escape argument which can be applied to previously transformed data.\n\n\n\nformat_tt(\n x,\n i = NULL,\n j = NULL,\n digits = getOption(\"tinytable_format_digits\", default = NULL),\n num_fmt = getOption(\"tinytable_format_num_fmt\", default = \"significant\"),\n num_zero = getOption(\"tinytable_format_num_zero\", default = FALSE),\n num_suffix = getOption(\"tinytable_format_num_suffix\", default = FALSE),\n num_mark_big = getOption(\"tinytable_format_num_mark_big\", default = \"\"),\n num_mark_dec = getOption(\"tinytable_format_num_mark_dec\", default = getOption(\"OutDec\",\n default = \".\")),\n date = getOption(\"tinytable_format_date\", default = \"%Y-%m-%d\"),\n bool = getOption(\"tinytable_format_bool\", default = function(column)\n tools::toTitleCase(tolower(column))),\n other = getOption(\"tinytable_format_other\", default = as.character),\n replace = getOption(\"tinytable_format_replace\", default = TRUE),\n escape = getOption(\"tinytable_format_escape\", default = FALSE),\n markdown = getOption(\"tinytable_format_markdown\", default = FALSE),\n quarto = getOption(\"tinytable_format_quarto\", default = FALSE),\n fn = getOption(\"tinytable_format_fn\", default = NULL),\n sprintf = getOption(\"tinytable_format_sprintf\", default = NULL),\n ...\n)\n\n\n\n\n\n\n\nx\n\n\nA data frame or a vector to be formatted.\n\n\n\n\ni\n\n\nRow indices where the formatting should be applied.\n\n\n\n\nj\n\n\nColumn indices where the styling should be applied. Can be:\n\n\nInteger vectors indicating column positions.\n\n\nCharacter vector indicating column names.\n\n\nA single string specifying a Perl-style regular expression used to match column names.\n\n\n\n\n\n\ndigits\n\n\nNumber of significant digits or decimal places.\n\n\n\n\nnum_fmt\n\n\nThe format for numeric values; one of ‘significant’, ‘significant_cell’, ‘decimal’, or ‘scientific’.\n\n\n\n\nnum_zero\n\n\nLogical; if TRUE, trailing zeros are kept in \"decimal\" format (but not in \"significant\" format).\n\n\n\n\nnum_suffix\n\n\nLogical; if TRUE display short numbers with digits significant digits and K (thousands), M (millions), B (billions), or T (trillions) suffixes.\n\n\n\n\nnum_mark_big\n\n\nCharacter to use as a thousands separator.\n\n\n\n\nnum_mark_dec\n\n\nDecimal mark character. Default is the global option ‘OutDec’.\n\n\n\n\ndate\n\n\nA string passed to the format() function, such as \"%Y-%m-%d\". See the \"Details\" section in ?strptime\n\n\n\n\nbool\n\n\nA function to format logical columns. Defaults to title case.\n\n\n\n\nother\n\n\nA function to format columns of other types. Defaults to as.character().\n\n\n\n\nreplace\n\n\nLogical, String or Named list of vectors\n\n\nTRUE: Replace NA by an empty string.\n\n\nFALSE: Print NA as the string \"NA\".\n\n\nString: Replace NA entries by the user-supplied string.\n\n\nNamed list: Replace matching elements of the vectors in the list by theirs names. Example:\n\n\nlist(“-” = c(NA, NaN), “Tiny” = -Inf, “Massive” = Inf)\n\n\n\n\n\n\n\n\nescape\n\n\nLogical or \"latex\" or \"html\". If TRUE, escape special characters to display them as text in the format of the output of a tt() table.\n\n\nIf i and j are both NULL, escape all cells, column names, caption, notes, and spanning labels created by group_tt().\n\n\n\n\n\n\nmarkdown\n\n\nLogical; if TRUE, render markdown syntax in cells. Ex: italicized text is properly italicized in HTML and LaTeX.\n\n\n\n\nquarto\n\n\nLogical. Enable Quarto data processing and wrap cell content in a data-qmd span (HTML) or macro (LaTeX). See warnings in the Global Options section below.\n\n\n\n\nfn\n\n\nFunction for custom formatting. Accepts a vector and returns a character vector of the same length.\n\n\n\n\nsprintf\n\n\nString passed to the ?sprintf function to format numbers or interpolate strings with a user-defined pattern (similar to the glue package, but using Base R).\n\n\n\n\n…\n\n\nAdditional arguments are ignored.\n\n\n\n\n\n\nA data frame with formatted columns.\n\n\n\n\nWhen the x data frame includes row names, tinytable can bind them to the first column (without an empty string string as column name). This global option triggers this behavior:\n\noptions(tinytable_tt_rownames = TRUE)\n\nx <- mtcars[1:3, 1:3]\ntt(x)\n\noptions(tinytable_tt_rownames = FALSE)\n\n\n\nThe format_tt(quarto=TRUE) argument activates Quarto data processing for specific cells. This funcationality comes with a few warnings:\n\n\nCurrently, Quarto provides a LaTeX macro, but it does not appear to do anything with it. References and markdown codes may not be processed as expected in LaTeX.\n\n\nQuarto data processing can enter in conflict with tinytable styling or formatting options. See below for how to disable it.\n\n\noptions(tinytable_quarto_disable_processing = TRUE)\nDisable Quarto processing of cell content. Setting this global option to FALSE may lead to conflicts with some tinytable features, but it also allows use of markdown and Quarto-specific code in table cells, such as cross-references.\n\nx <- data.frame(Math = \"x^2^\", Citation = \"@Lovelace1842\")\nfn <- function(z) sprintf(\"<span data-qmd='%s'></span>\", z)\ntt(x) |> format_tt(i = 1, fn = fn)\n\n\nSee this link for more details: https://quarto.org/docs/authoring/tables.html#disabling-quarto-table-processing\n\n\n\nEXPERIMENTAL options(tinytable_html_mathjax = TRUE) inserts MathJax scripts in the HTML document. Warning: This may conflict with other elements of the page if MathJax is otherwise loaded.\n\n\n\n\n\noptions(tinytable_save_pdf_clean = TRUE) deletes temporary and log files.\n\n\noptions(tinytable_save_pdf_engine = “xelatex”): \"xelatex\", \"pdflatex\", \"lualatex\"\n\n\n\n\n\n\nlibrary(\"tinytable\")\n\ndat <- data.frame(\n a = rnorm(3, mean = 10000),\n b = rnorm(3, 10000))\ntab <- tt(dat)\nformat_tt(tab,\n digits = 2,\n num_mark_dec = \",\",\n num_mark_big = \" \")\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n \n \n \n \n \n 10 000\n 10 001\n \n \n 9 999\n 9 999\n \n \n 10 001\n 9 999\n \n \n \n \n\n\nk <- tt(data.frame(x = c(0.000123456789, 12.4356789)))\nformat_tt(k, digits = 2, num_fmt = \"significant_cell\")\n\n\n\n \n\n \n \n \n \n \n \n x\n \n \n \n \n \n 0.00012\n \n \n 12\n \n \n \n \n\n\ndat <- data.frame(\n a = c(\"Burger\", \"Halloumi\", \"Tofu\", \"Beans\"),\n b = c(1.43202, 201.399, 0.146188, 0.0031),\n c = c(98938272783457, 7288839482, 29111727, 93945))\ntt(dat) |>\n format_tt(j = \"a\", sprintf = \"Food: %s\") |>\n format_tt(j = 2, digits = 1, num_fmt = \"decimal\", num_zero = TRUE) |>\n format_tt(j = \"c\", digits = 2, num_suffix = TRUE)\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n c\n \n \n \n \n \n Food: Burger\n 1.4\n 99T\n \n \n Food: Halloumi\n 201.4\n 7.3B\n \n \n Food: Tofu\n 0.1\n 29M\n \n \n Food: Beans\n 0.0\n 94K\n \n \n \n \n\n\ny <- tt(data.frame(x = c(123456789.678, 12435.6789)))\nformat_tt(y, digits=3, num_mark_big=\" \")\n\n\n\n \n\n \n \n \n \n \n \n x\n \n \n \n \n \n 123 456 790\n \n \n 12 436\n \n \n \n \n\n\nx <- tt(data.frame(Text = c(\"_italicized text_\", \"__bold text__\")))\nformat_tt(x, markdown=TRUE)\n\n\n\n \n\n \n \n \n \n \n \n Text\n \n \n \n \n \n italicized text\n \n \n bold text\n \n \n \n \n\n\ntab <- data.frame(a = c(NA, 1, 2), b = c(3, NA, 5))\ntt(tab) |> format_tt(replace = \"-\")\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n \n \n \n \n \n -\n 3\n \n \n 1\n -\n \n \n 2\n 5\n \n \n \n \n\n\ndat <- data.frame(\n \"LaTeX\" = c(\"Dollars $\", \"Percent %\", \"Underscore _\"),\n \"HTML\" = c(\"<br>\", \"<sup>4</sup>\", \"<emph>blah</emph>\")\n)\ntt(dat) |> format_tt(escape = TRUE) \n\n\n\n \n\n \n \n \n \n \n \n LaTeX\n HTML\n \n \n \n \n \n Dollars $\n <br>\n \n \n Percent %\n <sup>4</sup>\n \n \n Underscore _\n <emph>blah</emph>", "crumbs": [ "Tutorial (PDF)", "Functions", @@ -479,7 +479,7 @@ "href": "man/format_tt.html#format-columns-of-a-data-frame", "title": "tinytable", "section": "", - "text": "This function formats the columns of a data frame based on the column type (logical, date, numeric). It allows various formatting options like significant digits, decimal points, and scientific notation. It also includes custom formatting for date and boolean values. If this function is applied several times to the same cell, the last transformation is retained and the previous calls are ignored, except for the escape argument which can be applied to previously transformed data.\n\n\n\nformat_tt(\n x,\n i = NULL,\n j = NULL,\n digits = getOption(\"tinytable_format_digits\", default = NULL),\n num_fmt = getOption(\"tinytable_format_num_fmt\", default = \"significant\"),\n num_zero = getOption(\"tinytable_format_num_zero\", default = FALSE),\n num_suffix = getOption(\"tinytable_format_num_suffix\", default = FALSE),\n num_mark_big = getOption(\"tinytable_format_num_mark_big\", default = \"\"),\n num_mark_dec = getOption(\"tinytable_format_num_mark_dec\", default = getOption(\"OutDec\",\n default = \".\")),\n date = getOption(\"tinytable_format_date\", default = \"%Y-%m-%d\"),\n bool = getOption(\"tinytable_format_bool\", default = function(column)\n tools::toTitleCase(tolower(column))),\n other = getOption(\"tinytable_format_other\", default = as.character),\n replace = getOption(\"tinytable_format_replace\", default = TRUE),\n escape = getOption(\"tinytable_format_escape\", default = FALSE),\n markdown = getOption(\"tinytable_format_markdown\", default = FALSE),\n quarto = getOption(\"tinytable_format_quarto\", default = FALSE),\n fn = getOption(\"tinytable_format_fn\", default = NULL),\n sprintf = getOption(\"tinytable_format_sprintf\", default = NULL),\n ...\n)\n\n\n\n\n\n\n\nx\n\n\nA data frame or a vector to be formatted.\n\n\n\n\ni\n\n\nRow indices where the formatting should be applied.\n\n\n\n\nj\n\n\nColumn indices where the styling should be applied. Can be:\n\n\nInteger vectors indicating column positions.\n\n\nCharacter vector indicating column names.\n\n\nA single string specifying a Perl-style regular expression used to match column names.\n\n\n\n\n\n\ndigits\n\n\nNumber of significant digits or decimal places.\n\n\n\n\nnum_fmt\n\n\nThe format for numeric values; one of ‘significant’, ‘significant_cell’, ‘decimal’, or ‘scientific’.\n\n\n\n\nnum_zero\n\n\nLogical; if TRUE, trailing zeros are kept in \"decimal\" format (but not in \"significant\" format).\n\n\n\n\nnum_suffix\n\n\nLogical; if TRUE display short numbers with digits significant digits and K (thousands), M (millions), B (billions), or T (trillions) suffixes.\n\n\n\n\nnum_mark_big\n\n\nCharacter to use as a thousands separator.\n\n\n\n\nnum_mark_dec\n\n\nDecimal mark character. Default is the global option ‘OutDec’.\n\n\n\n\ndate\n\n\nA string passed to the format() function, such as \"%Y-%m-%d\". See the \"Details\" section in ?strptime\n\n\n\n\nbool\n\n\nA function to format logical columns. Defaults to title case.\n\n\n\n\nother\n\n\nA function to format columns of other types. Defaults to as.character().\n\n\n\n\nreplace\n\n\nLogical, String or Named list of vectors\n\n\nTRUE: Replace NA by an empty string.\n\n\nFALSE: Print NA as the string \"NA\".\n\n\nString: Replace NA entries by the user-supplied string.\n\n\nNamed list: Replace matching elements of the vectors in the list by theirs names. Example:\n\n\nlist(“-” = c(NA, NaN), “Tiny” = -Inf, “Massive” = Inf)\n\n\n\n\n\n\n\n\nescape\n\n\nLogical or \"latex\" or \"html\". If TRUE, escape special characters to display them as text in the format of the output of a tt() table.\n\n\nIf i and j are both NULL, escape all cells, column names, caption, notes, and spanning labels created by group_tt().\n\n\n\n\n\n\nmarkdown\n\n\nLogical; if TRUE, render markdown syntax in cells. Ex: italicized text is properly italicized in HTML and LaTeX.\n\n\n\n\nquarto\n\n\nLogical. Enable Quarto data processing and wrap cell content in a data-qmd span (HTML) or macro (LaTeX). See warnings in the Global Options section below.\n\n\n\n\nfn\n\n\nFunction for custom formatting. Accepts a vector and returns a character vector of the same length.\n\n\n\n\nsprintf\n\n\nString passed to the ?sprintf function to format numbers or interpolate strings with a user-defined pattern (similar to the glue package, but using Base R).\n\n\n\n\n…\n\n\nAdditional arguments are ignored.\n\n\n\n\n\n\nA data frame with formatted columns.\n\n\n\n\nWhen the x data frame includes row names, tinytable can bind them to the first column (without an empty string string as column name). This global option triggers this behavior:\n\noptions(tinytable_tt_rownames = TRUE)\n\nx <- mtcars[1:3, 1:3]\ntt(x)\n\noptions(tinytable_tt_rownames = FALSE)\n\n\n\nThe format_tt(quarto=TRUE) argument activates Quarto data processing for specific cells. This funcationality comes with a few warnings:\n\n\nCurrently, Quarto provides a LaTeX macro, but it does not appear to do anything with it. References and markdown codes may not be processed as expected in LaTeX.\n\n\nQuarto data processing can enter in conflict with tinytable styling or formatting options. See below for how to disable it.\n\n\noptions(tinytable_quarto_disable_processing = TRUE)\nDisable Quarto processing of cell content. Setting this global option to FALSE may lead to conflicts with some tinytable features, but it also allows use of markdown and Quarto-specific code in table cells, such as cross-references.\n\nx <- data.frame(Math = \"x^2^\", Citation = \"@Lovelace1842\")\nfn <- function(z) sprintf(\"<span data-qmd='%s'></span>\", z)\ntt(x) |> format_tt(i = 1, fn = fn)\n\n\nSee this link for more details: https://quarto.org/docs/authoring/tables.html#disabling-quarto-table-processing\n\n\n\nEXPERIMENTAL options(tinytable_html_mathjax = TRUE) inserts MathJax scripts in the HTML document. Warning: This may conflict with other elements of the page if MathJax is otherwise loaded.\n\n\n\n\n\noptions(tinytable_save_pdf_clean = TRUE) deletes temporary and log files.\n\n\noptions(tinytable_save_pdf_engine = “xelatex”): \"xelatex\", \"pdflatex\", \"lualatex\"\n\n\n\n\n\n\nlibrary(\"tinytable\")\n\ndat <- data.frame(\n a = rnorm(3, mean = 10000),\n b = rnorm(3, 10000))\ntab <- tt(dat)\nformat_tt(tab,\n digits = 2,\n num_mark_dec = \",\",\n num_mark_big = \" \")\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n \n \n \n \n \n 10 002\n 9 999\n \n \n 9 999\n 10 000\n \n \n 10 001\n 10 001\n \n \n \n \n\n\nk <- tt(data.frame(x = c(0.000123456789, 12.4356789)))\nformat_tt(k, digits = 2, num_fmt = \"significant_cell\")\n\n\n\n \n\n \n \n \n \n \n \n x\n \n \n \n \n \n 0.00012\n \n \n 12\n \n \n \n \n\n\ndat <- data.frame(\n a = c(\"Burger\", \"Halloumi\", \"Tofu\", \"Beans\"),\n b = c(1.43202, 201.399, 0.146188, 0.0031),\n c = c(98938272783457, 7288839482, 29111727, 93945))\ntt(dat) |>\n format_tt(j = \"a\", sprintf = \"Food: %s\") |>\n format_tt(j = 2, digits = 1, num_fmt = \"decimal\", num_zero = TRUE) |>\n format_tt(j = \"c\", digits = 2, num_suffix = TRUE)\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n c\n \n \n \n \n \n Food: Burger\n 1.4\n 99T\n \n \n Food: Halloumi\n 201.4\n 7.3B\n \n \n Food: Tofu\n 0.1\n 29M\n \n \n Food: Beans\n 0.0\n 94K\n \n \n \n \n\n\ny <- tt(data.frame(x = c(123456789.678, 12435.6789)))\nformat_tt(y, digits=3, num_mark_big=\" \")\n\n\n\n \n\n \n \n \n \n \n \n x\n \n \n \n \n \n 123 456 790\n \n \n 12 436\n \n \n \n \n\n\nx <- tt(data.frame(Text = c(\"_italicized text_\", \"__bold text__\")))\nformat_tt(x, markdown=TRUE)\n\n\n\n \n\n \n \n \n \n \n \n Text\n \n \n \n \n \n italicized text\n \n \n bold text\n \n \n \n \n\n\ntab <- data.frame(a = c(NA, 1, 2), b = c(3, NA, 5))\ntt(tab) |> format_tt(replace = \"-\")\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n \n \n \n \n \n -\n 3\n \n \n 1\n -\n \n \n 2\n 5\n \n \n \n \n\n\ndat <- data.frame(\n \"LaTeX\" = c(\"Dollars $\", \"Percent %\", \"Underscore _\"),\n \"HTML\" = c(\"<br>\", \"<sup>4</sup>\", \"<emph>blah</emph>\")\n)\ntt(dat) |> format_tt(escape = TRUE) \n\n\n\n \n\n \n \n \n \n \n \n LaTeX\n HTML\n \n \n \n \n \n Dollars $\n <br>\n \n \n Percent %\n <sup>4</sup>\n \n \n Underscore _\n <emph>blah</emph>", + "text": "This function formats the columns of a data frame based on the column type (logical, date, numeric). It allows various formatting options like significant digits, decimal points, and scientific notation. It also includes custom formatting for date and boolean values. If this function is applied several times to the same cell, the last transformation is retained and the previous calls are ignored, except for the escape argument which can be applied to previously transformed data.\n\n\n\nformat_tt(\n x,\n i = NULL,\n j = NULL,\n digits = getOption(\"tinytable_format_digits\", default = NULL),\n num_fmt = getOption(\"tinytable_format_num_fmt\", default = \"significant\"),\n num_zero = getOption(\"tinytable_format_num_zero\", default = FALSE),\n num_suffix = getOption(\"tinytable_format_num_suffix\", default = FALSE),\n num_mark_big = getOption(\"tinytable_format_num_mark_big\", default = \"\"),\n num_mark_dec = getOption(\"tinytable_format_num_mark_dec\", default = getOption(\"OutDec\",\n default = \".\")),\n date = getOption(\"tinytable_format_date\", default = \"%Y-%m-%d\"),\n bool = getOption(\"tinytable_format_bool\", default = function(column)\n tools::toTitleCase(tolower(column))),\n other = getOption(\"tinytable_format_other\", default = as.character),\n replace = getOption(\"tinytable_format_replace\", default = TRUE),\n escape = getOption(\"tinytable_format_escape\", default = FALSE),\n markdown = getOption(\"tinytable_format_markdown\", default = FALSE),\n quarto = getOption(\"tinytable_format_quarto\", default = FALSE),\n fn = getOption(\"tinytable_format_fn\", default = NULL),\n sprintf = getOption(\"tinytable_format_sprintf\", default = NULL),\n ...\n)\n\n\n\n\n\n\n\nx\n\n\nA data frame or a vector to be formatted.\n\n\n\n\ni\n\n\nRow indices where the formatting should be applied.\n\n\n\n\nj\n\n\nColumn indices where the styling should be applied. Can be:\n\n\nInteger vectors indicating column positions.\n\n\nCharacter vector indicating column names.\n\n\nA single string specifying a Perl-style regular expression used to match column names.\n\n\n\n\n\n\ndigits\n\n\nNumber of significant digits or decimal places.\n\n\n\n\nnum_fmt\n\n\nThe format for numeric values; one of ‘significant’, ‘significant_cell’, ‘decimal’, or ‘scientific’.\n\n\n\n\nnum_zero\n\n\nLogical; if TRUE, trailing zeros are kept in \"decimal\" format (but not in \"significant\" format).\n\n\n\n\nnum_suffix\n\n\nLogical; if TRUE display short numbers with digits significant digits and K (thousands), M (millions), B (billions), or T (trillions) suffixes.\n\n\n\n\nnum_mark_big\n\n\nCharacter to use as a thousands separator.\n\n\n\n\nnum_mark_dec\n\n\nDecimal mark character. Default is the global option ‘OutDec’.\n\n\n\n\ndate\n\n\nA string passed to the format() function, such as \"%Y-%m-%d\". See the \"Details\" section in ?strptime\n\n\n\n\nbool\n\n\nA function to format logical columns. Defaults to title case.\n\n\n\n\nother\n\n\nA function to format columns of other types. Defaults to as.character().\n\n\n\n\nreplace\n\n\nLogical, String or Named list of vectors\n\n\nTRUE: Replace NA by an empty string.\n\n\nFALSE: Print NA as the string \"NA\".\n\n\nString: Replace NA entries by the user-supplied string.\n\n\nNamed list: Replace matching elements of the vectors in the list by theirs names. Example:\n\n\nlist(“-” = c(NA, NaN), “Tiny” = -Inf, “Massive” = Inf)\n\n\n\n\n\n\n\n\nescape\n\n\nLogical or \"latex\" or \"html\". If TRUE, escape special characters to display them as text in the format of the output of a tt() table.\n\n\nIf i and j are both NULL, escape all cells, column names, caption, notes, and spanning labels created by group_tt().\n\n\n\n\n\n\nmarkdown\n\n\nLogical; if TRUE, render markdown syntax in cells. Ex: italicized text is properly italicized in HTML and LaTeX.\n\n\n\n\nquarto\n\n\nLogical. Enable Quarto data processing and wrap cell content in a data-qmd span (HTML) or macro (LaTeX). See warnings in the Global Options section below.\n\n\n\n\nfn\n\n\nFunction for custom formatting. Accepts a vector and returns a character vector of the same length.\n\n\n\n\nsprintf\n\n\nString passed to the ?sprintf function to format numbers or interpolate strings with a user-defined pattern (similar to the glue package, but using Base R).\n\n\n\n\n…\n\n\nAdditional arguments are ignored.\n\n\n\n\n\n\nA data frame with formatted columns.\n\n\n\n\nWhen the x data frame includes row names, tinytable can bind them to the first column (without an empty string string as column name). This global option triggers this behavior:\n\noptions(tinytable_tt_rownames = TRUE)\n\nx <- mtcars[1:3, 1:3]\ntt(x)\n\noptions(tinytable_tt_rownames = FALSE)\n\n\n\nThe format_tt(quarto=TRUE) argument activates Quarto data processing for specific cells. This funcationality comes with a few warnings:\n\n\nCurrently, Quarto provides a LaTeX macro, but it does not appear to do anything with it. References and markdown codes may not be processed as expected in LaTeX.\n\n\nQuarto data processing can enter in conflict with tinytable styling or formatting options. See below for how to disable it.\n\n\noptions(tinytable_quarto_disable_processing = TRUE)\nDisable Quarto processing of cell content. Setting this global option to FALSE may lead to conflicts with some tinytable features, but it also allows use of markdown and Quarto-specific code in table cells, such as cross-references.\n\nx <- data.frame(Math = \"x^2^\", Citation = \"@Lovelace1842\")\nfn <- function(z) sprintf(\"<span data-qmd='%s'></span>\", z)\ntt(x) |> format_tt(i = 1, fn = fn)\n\n\nSee this link for more details: https://quarto.org/docs/authoring/tables.html#disabling-quarto-table-processing\n\n\n\nEXPERIMENTAL options(tinytable_html_mathjax = TRUE) inserts MathJax scripts in the HTML document. Warning: This may conflict with other elements of the page if MathJax is otherwise loaded.\n\n\n\n\n\noptions(tinytable_save_pdf_clean = TRUE) deletes temporary and log files.\n\n\noptions(tinytable_save_pdf_engine = “xelatex”): \"xelatex\", \"pdflatex\", \"lualatex\"\n\n\n\n\n\n\nlibrary(\"tinytable\")\n\ndat <- data.frame(\n a = rnorm(3, mean = 10000),\n b = rnorm(3, 10000))\ntab <- tt(dat)\nformat_tt(tab,\n digits = 2,\n num_mark_dec = \",\",\n num_mark_big = \" \")\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n \n \n \n \n \n 10 000\n 10 001\n \n \n 9 999\n 9 999\n \n \n 10 001\n 9 999\n \n \n \n \n\n\nk <- tt(data.frame(x = c(0.000123456789, 12.4356789)))\nformat_tt(k, digits = 2, num_fmt = \"significant_cell\")\n\n\n\n \n\n \n \n \n \n \n \n x\n \n \n \n \n \n 0.00012\n \n \n 12\n \n \n \n \n\n\ndat <- data.frame(\n a = c(\"Burger\", \"Halloumi\", \"Tofu\", \"Beans\"),\n b = c(1.43202, 201.399, 0.146188, 0.0031),\n c = c(98938272783457, 7288839482, 29111727, 93945))\ntt(dat) |>\n format_tt(j = \"a\", sprintf = \"Food: %s\") |>\n format_tt(j = 2, digits = 1, num_fmt = \"decimal\", num_zero = TRUE) |>\n format_tt(j = \"c\", digits = 2, num_suffix = TRUE)\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n c\n \n \n \n \n \n Food: Burger\n 1.4\n 99T\n \n \n Food: Halloumi\n 201.4\n 7.3B\n \n \n Food: Tofu\n 0.1\n 29M\n \n \n Food: Beans\n 0.0\n 94K\n \n \n \n \n\n\ny <- tt(data.frame(x = c(123456789.678, 12435.6789)))\nformat_tt(y, digits=3, num_mark_big=\" \")\n\n\n\n \n\n \n \n \n \n \n \n x\n \n \n \n \n \n 123 456 790\n \n \n 12 436\n \n \n \n \n\n\nx <- tt(data.frame(Text = c(\"_italicized text_\", \"__bold text__\")))\nformat_tt(x, markdown=TRUE)\n\n\n\n \n\n \n \n \n \n \n \n Text\n \n \n \n \n \n italicized text\n \n \n bold text\n \n \n \n \n\n\ntab <- data.frame(a = c(NA, 1, 2), b = c(3, NA, 5))\ntt(tab) |> format_tt(replace = \"-\")\n\n\n\n \n\n \n \n \n \n \n \n a\n b\n \n \n \n \n \n -\n 3\n \n \n 1\n -\n \n \n 2\n 5\n \n \n \n \n\n\ndat <- data.frame(\n \"LaTeX\" = c(\"Dollars $\", \"Percent %\", \"Underscore _\"),\n \"HTML\" = c(\"<br>\", \"<sup>4</sup>\", \"<emph>blah</emph>\")\n)\ntt(dat) |> format_tt(escape = TRUE) \n\n\n\n \n\n \n \n \n \n \n \n LaTeX\n HTML\n \n \n \n \n \n Dollars $\n <br>\n \n \n Percent %\n <sup>4</sup>\n \n \n Underscore _\n <emph>blah</emph>", "crumbs": [ "Tutorial (PDF)", "Functions", @@ -906,7 +906,7 @@ "href": "vignettes/custom.html", "title": "Customization", "section": "", - "text": "library(tinytable)\noptions(tinytable_tt_digits = 3)\noptions(tinytable_theme_placement_latex_float = \"H\")\nx <- mtcars[1:4, 1:5]\n\n\n\n\n\nThe Bootstrap framework provides a number of built-in themes to style tables, using “classes.” To use them, we call style_tt() with the bootstrap_class argument. A list of available Bootstrap classes can be found here: https://getbootstrap.com/docs/5.3/content/tables/\nTo produce a more condensed or “small” table, we use the table-sm class:\n\ntt(x) |> style_tt(bootstrap_class = \"table-sm\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\nTo produce a “bordered” table, we use the table-bordered class:\n\ntt(x) |> style_tt(bootstrap_class = \"table table-bordered\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\nWe can also combine several Bootstrap classes. Here, we get a table with the “hover” feature:\n\ntt(x) |> style_tt(\n bootstrap_class = \"table table-hover\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\n\n\n\nThe style_tt() function allows us to declare CSS properties and values for individual cells, columns, or rows of a table. For example, if we want to make the first column bold, we could do:\n\ntt(x) |>\n style_tt(j = 1, bootstrap_css = \"font-weight: bold; color: red;\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\n\n\n\nFor 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.\n\ncss_rule <- \"\n.mytable {\n background: linear-gradient(45deg, #EA8D8D, #A890FE);\n width: 600px;\n border-collapse: collapse;\n overflow: hidden;\n box-shadow: 0 0 20px rgba(0,0,0,0.1);\n}\n\n.mytable th,\n.mytable td {\n padding: 5px;\n background-color: rgba(255,255,255,0.2);\n color: #fff;\n}\n\n.mytable tbody tr:hover {\n background-color: rgba(255,255,255,0.3);\n}\n\n.mytable tbody td:hover:before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: -9999px;\n bottom: -9999px;\n background-color: rgba(255,255,255,0.2);\n z-index: -1;\n}\n\"\n\ntt(x, width = 2/3) |> \n style_tt(\n j = 1:5,\n align = \"ccccc\",\n bootstrap_class = \"table mytable\",\n bootstrap_css_rule = css_rule)\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\nAnd here’s another example:\n\ncss <- \"\n.squirreltable {\n background-size: cover;\n background-position: center;\n background-image: url('https://user-images.githubusercontent.com/987057/82732352-b9aabf00-9cda-11ea-92a6-26750cf097d0.png');\n --bs-table-bg: transparent;\n}\n\"\n\ntt(mtcars[1:10, 1:8]) |>\n style_tt(\n bootstrap_class = \"table table-borderless squirreltable\", \n bootstrap_css_rule = css)\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n wt\n qsec\n vs\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n 2.62\n 16.5\n 0\n \n \n 21 \n 6\n 160\n 110\n 3.9 \n 2.88\n 17 \n 0\n \n \n 22.8\n 4\n 108\n 93\n 3.85\n 2.32\n 18.6\n 1\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n 3.21\n 19.4\n 1\n \n \n 18.7\n 8\n 360\n 175\n 3.15\n 3.44\n 17 \n 0\n \n \n 18.1\n 6\n 225\n 105\n 2.76\n 3.46\n 20.2\n 1\n \n \n 14.3\n 8\n 360\n 245\n 3.21\n 3.57\n 15.8\n 0\n \n \n 24.4\n 4\n 147\n 62\n 3.69\n 3.19\n 20 \n 1\n \n \n 22.8\n 4\n 141\n 95\n 3.92\n 3.15\n 22.9\n 1\n \n \n 19.2\n 6\n 168\n 123\n 3.92\n 3.44\n 18.3\n 1\n \n \n \n \n\n\n\n\n\n\n\nThe LaTeX / PDF customization options described in this section are not available for HTML documents. Please refer to the PDF documentation hosted on the website to read this part of the tutorial.\n\n\n\n\n\n\n\n\n\n\n\n\ntinytable is a great complement to Shiny for displaying HTML tables in a web app. The styling in a tinytable is applied by JavaScript functions and CSS. Thus, to ensure that this styling is preserved in a Shiny app, one strategy is to bake the entire page, save it in a temporary file, and load it using the includeHTML function from the shiny package. This approach is illustrated in this minimal example:\n\nlibrary(\"shiny\")\nlibrary(\"tinytable\")\n\nfn <- paste(tempfile(), \".html\")\ntab <- tt(mtcars[1:5, 1:4]) |> \n style_tt(i = 0:5, color = \"orange\", background = \"black\") |> \n save_tt(fn) \n\nshinyApp(\n ui = fluidPage(\n fluidRow(column(12, h1(\"This is test of tinytable\"), \n shiny::includeHTML(fn)))), \n server = function(input, output) { \n }\n)", + "text": "library(tinytable)\noptions(tinytable_tt_digits = 3)\noptions(tinytable_theme_placement_latex_float = \"H\")\nx <- mtcars[1:4, 1:5]\n\n\n\n\n\nThe Bootstrap framework provides a number of built-in themes to style tables, using “classes.” To use them, we call style_tt() with the bootstrap_class argument. A list of available Bootstrap classes can be found here: https://getbootstrap.com/docs/5.3/content/tables/\nTo produce a more condensed or “small” table, we use the table-sm class:\n\ntt(x) |> style_tt(bootstrap_class = \"table table-sm\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\nTo produce a “bordered” table, we use the table-bordered class:\n\ntt(x) |> style_tt(bootstrap_class = \"table table-bordered\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\nWe can also combine several Bootstrap classes. Here, we get a table with the “hover” feature:\n\ntt(x) |> style_tt(\n bootstrap_class = \"table table-hover\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\n\n\n\nThe style_tt() function allows us to declare CSS properties and values for individual cells, columns, or rows of a table. For example, if we want to make the first column bold, we could do:\n\ntt(x) |>\n style_tt(j = 1, bootstrap_css = \"font-weight: bold; color: red;\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\n\n\n\nFor 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.\n\ncss_rule <- \"\n.mytable {\n background: linear-gradient(45deg, #EA8D8D, #A890FE);\n width: 600px;\n border-collapse: collapse;\n overflow: hidden;\n box-shadow: 0 0 20px rgba(0,0,0,0.1);\n}\n\n.mytable th,\n.mytable td {\n padding: 5px;\n background-color: rgba(255,255,255,0.2);\n color: #fff;\n}\n\n.mytable tbody tr:hover {\n background-color: rgba(255,255,255,0.3);\n}\n\n.mytable tbody td:hover:before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: -9999px;\n bottom: -9999px;\n background-color: rgba(255,255,255,0.2);\n z-index: -1;\n}\n\"\n\ntt(x, width = 2/3) |> \n style_tt(\n j = 1:5,\n align = \"ccccc\",\n bootstrap_class = \"table mytable\",\n bootstrap_css_rule = css_rule)\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\nAnd here’s another example:\n\ncss <- \"\n.squirreltable {\n background-size: cover;\n background-position: center;\n background-image: url('https://user-images.githubusercontent.com/987057/82732352-b9aabf00-9cda-11ea-92a6-26750cf097d0.png');\n --bs-table-bg: transparent;\n}\n\"\n\ntt(mtcars[1:10, 1:8]) |>\n style_tt(\n bootstrap_class = \"table table-borderless squirreltable\", \n bootstrap_css_rule = css)\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n wt\n qsec\n vs\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n 2.62\n 16.5\n 0\n \n \n 21 \n 6\n 160\n 110\n 3.9 \n 2.88\n 17 \n 0\n \n \n 22.8\n 4\n 108\n 93\n 3.85\n 2.32\n 18.6\n 1\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n 3.21\n 19.4\n 1\n \n \n 18.7\n 8\n 360\n 175\n 3.15\n 3.44\n 17 \n 0\n \n \n 18.1\n 6\n 225\n 105\n 2.76\n 3.46\n 20.2\n 1\n \n \n 14.3\n 8\n 360\n 245\n 3.21\n 3.57\n 15.8\n 0\n \n \n 24.4\n 4\n 147\n 62\n 3.69\n 3.19\n 20 \n 1\n \n \n 22.8\n 4\n 141\n 95\n 3.92\n 3.15\n 22.9\n 1\n \n \n 19.2\n 6\n 168\n 123\n 3.92\n 3.44\n 18.3\n 1\n \n \n \n \n\n\n\n\n\n\n\nThe LaTeX / PDF customization options described in this section are not available for HTML documents. Please refer to the PDF documentation hosted on the website to read this part of the tutorial.\n\n\n\n\n\n\n\n\n\n\n\n\ntinytable is a great complement to Shiny for displaying HTML tables in a web app. The styling in a tinytable is applied by JavaScript functions and CSS. Thus, to ensure that this styling is preserved in a Shiny app, one strategy is to bake the entire page, save it in a temporary file, and load it using the includeHTML function from the shiny package. This approach is illustrated in this minimal example:\n\nlibrary(\"shiny\")\nlibrary(\"tinytable\")\n\nfn <- paste(tempfile(), \".html\")\ntab <- tt(mtcars[1:5, 1:4]) |> \n style_tt(i = 0:5, color = \"orange\", background = \"black\") |> \n save_tt(fn) \n\nshinyApp(\n ui = fluidPage(\n fluidRow(column(12, h1(\"This is test of tinytable\"), \n shiny::includeHTML(fn)))), \n server = function(input, output) { \n }\n)", "crumbs": [ "Tutorial (PDF)", "Tutorial", @@ -918,7 +918,7 @@ "href": "vignettes/custom.html#html", "title": "Customization", "section": "", - "text": "The Bootstrap framework provides a number of built-in themes to style tables, using “classes.” To use them, we call style_tt() with the bootstrap_class argument. A list of available Bootstrap classes can be found here: https://getbootstrap.com/docs/5.3/content/tables/\nTo produce a more condensed or “small” table, we use the table-sm class:\n\ntt(x) |> style_tt(bootstrap_class = \"table-sm\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\nTo produce a “bordered” table, we use the table-bordered class:\n\ntt(x) |> style_tt(bootstrap_class = \"table table-bordered\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\nWe can also combine several Bootstrap classes. Here, we get a table with the “hover” feature:\n\ntt(x) |> style_tt(\n bootstrap_class = \"table table-hover\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\n\n\n\nThe style_tt() function allows us to declare CSS properties and values for individual cells, columns, or rows of a table. For example, if we want to make the first column bold, we could do:\n\ntt(x) |>\n style_tt(j = 1, bootstrap_css = \"font-weight: bold; color: red;\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\n\n\n\nFor 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.\n\ncss_rule <- \"\n.mytable {\n background: linear-gradient(45deg, #EA8D8D, #A890FE);\n width: 600px;\n border-collapse: collapse;\n overflow: hidden;\n box-shadow: 0 0 20px rgba(0,0,0,0.1);\n}\n\n.mytable th,\n.mytable td {\n padding: 5px;\n background-color: rgba(255,255,255,0.2);\n color: #fff;\n}\n\n.mytable tbody tr:hover {\n background-color: rgba(255,255,255,0.3);\n}\n\n.mytable tbody td:hover:before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: -9999px;\n bottom: -9999px;\n background-color: rgba(255,255,255,0.2);\n z-index: -1;\n}\n\"\n\ntt(x, width = 2/3) |> \n style_tt(\n j = 1:5,\n align = \"ccccc\",\n bootstrap_class = \"table mytable\",\n bootstrap_css_rule = css_rule)\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\nAnd here’s another example:\n\ncss <- \"\n.squirreltable {\n background-size: cover;\n background-position: center;\n background-image: url('https://user-images.githubusercontent.com/987057/82732352-b9aabf00-9cda-11ea-92a6-26750cf097d0.png');\n --bs-table-bg: transparent;\n}\n\"\n\ntt(mtcars[1:10, 1:8]) |>\n style_tt(\n bootstrap_class = \"table table-borderless squirreltable\", \n bootstrap_css_rule = css)\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n wt\n qsec\n vs\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n 2.62\n 16.5\n 0\n \n \n 21 \n 6\n 160\n 110\n 3.9 \n 2.88\n 17 \n 0\n \n \n 22.8\n 4\n 108\n 93\n 3.85\n 2.32\n 18.6\n 1\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n 3.21\n 19.4\n 1\n \n \n 18.7\n 8\n 360\n 175\n 3.15\n 3.44\n 17 \n 0\n \n \n 18.1\n 6\n 225\n 105\n 2.76\n 3.46\n 20.2\n 1\n \n \n 14.3\n 8\n 360\n 245\n 3.21\n 3.57\n 15.8\n 0\n \n \n 24.4\n 4\n 147\n 62\n 3.69\n 3.19\n 20 \n 1\n \n \n 22.8\n 4\n 141\n 95\n 3.92\n 3.15\n 22.9\n 1\n \n \n 19.2\n 6\n 168\n 123\n 3.92\n 3.44\n 18.3\n 1", + "text": "The Bootstrap framework provides a number of built-in themes to style tables, using “classes.” To use them, we call style_tt() with the bootstrap_class argument. A list of available Bootstrap classes can be found here: https://getbootstrap.com/docs/5.3/content/tables/\nTo produce a more condensed or “small” table, we use the table-sm class:\n\ntt(x) |> style_tt(bootstrap_class = \"table table-sm\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\nTo produce a “bordered” table, we use the table-bordered class:\n\ntt(x) |> style_tt(bootstrap_class = \"table table-bordered\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\nWe can also combine several Bootstrap classes. Here, we get a table with the “hover” feature:\n\ntt(x) |> style_tt(\n bootstrap_class = \"table table-hover\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\n\n\n\nThe style_tt() function allows us to declare CSS properties and values for individual cells, columns, or rows of a table. For example, if we want to make the first column bold, we could do:\n\ntt(x) |>\n style_tt(j = 1, bootstrap_css = \"font-weight: bold; color: red;\")\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\n\n\n\nFor 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.\n\ncss_rule <- \"\n.mytable {\n background: linear-gradient(45deg, #EA8D8D, #A890FE);\n width: 600px;\n border-collapse: collapse;\n overflow: hidden;\n box-shadow: 0 0 20px rgba(0,0,0,0.1);\n}\n\n.mytable th,\n.mytable td {\n padding: 5px;\n background-color: rgba(255,255,255,0.2);\n color: #fff;\n}\n\n.mytable tbody tr:hover {\n background-color: rgba(255,255,255,0.3);\n}\n\n.mytable tbody td:hover:before {\n content: '';\n position: absolute;\n left: 0;\n right: 0;\n top: -9999px;\n bottom: -9999px;\n background-color: rgba(255,255,255,0.2);\n z-index: -1;\n}\n\"\n\ntt(x, width = 2/3) |> \n style_tt(\n j = 1:5,\n align = \"ccccc\",\n bootstrap_class = \"table mytable\",\n bootstrap_css_rule = css_rule)\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n \n \n 22.8\n 4\n 108\n 93\n 3.85\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n \n \n \n \n\n\n\nAnd here’s another example:\n\ncss <- \"\n.squirreltable {\n background-size: cover;\n background-position: center;\n background-image: url('https://user-images.githubusercontent.com/987057/82732352-b9aabf00-9cda-11ea-92a6-26750cf097d0.png');\n --bs-table-bg: transparent;\n}\n\"\n\ntt(mtcars[1:10, 1:8]) |>\n style_tt(\n bootstrap_class = \"table table-borderless squirreltable\", \n bootstrap_css_rule = css)\n\n\n\n \n\n \n \n \n \n \n \n mpg\n cyl\n disp\n hp\n drat\n wt\n qsec\n vs\n \n \n \n \n \n 21 \n 6\n 160\n 110\n 3.9 \n 2.62\n 16.5\n 0\n \n \n 21 \n 6\n 160\n 110\n 3.9 \n 2.88\n 17 \n 0\n \n \n 22.8\n 4\n 108\n 93\n 3.85\n 2.32\n 18.6\n 1\n \n \n 21.4\n 6\n 258\n 110\n 3.08\n 3.21\n 19.4\n 1\n \n \n 18.7\n 8\n 360\n 175\n 3.15\n 3.44\n 17 \n 0\n \n \n 18.1\n 6\n 225\n 105\n 2.76\n 3.46\n 20.2\n 1\n \n \n 14.3\n 8\n 360\n 245\n 3.21\n 3.57\n 15.8\n 0\n \n \n 24.4\n 4\n 147\n 62\n 3.69\n 3.19\n 20 \n 1\n \n \n 22.8\n 4\n 141\n 95\n 3.92\n 3.15\n 22.9\n 1\n \n \n 19.2\n 6\n 168\n 123\n 3.92\n 3.44\n 18.3\n 1", "crumbs": [ "Tutorial (PDF)", "Tutorial", diff --git a/vignettes/custom.html b/vignettes/custom.html index da84c78d..97144809 100644 --- a/vignettes/custom.html +++ b/vignettes/custom.html @@ -418,20 +418,20 @@

Bootstrap classes

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

To produce a more condensed or “small” table, we use the table-sm class:

-
tt(x) |> style_tt(bootstrap_class = "table-sm")
+
tt(x) |> style_tt(bootstrap_class = "table table-sm")
-
+
@@ -535,15 +535,15 @@

Bootstrap classes

-
+
@@ -648,15 +648,15 @@

Bootstrap classes

-
+
@@ -764,15 +764,15 @@

CSS declarations

-
+
@@ -926,15 +926,15 @@

CSS rules

-
+
@@ -1091,15 +1091,15 @@

CSS rules

-
+
diff --git a/vignettes/format.html b/vignettes/format.html index 47f5b75e..ad915d2f 100644 --- a/vignettes/format.html +++ b/vignettes/format.html @@ -441,15 +441,15 @@

Numbers, dates,
-

+
@@ -514,19 +514,19 @@

Numbers, dates,

- + - + - + @@ -552,15 +552,15 @@

Numbers, dates,
-

143002 1.431971-03-041971-02-06 True
201399 201.4 1970-02-241970-04-30 True
100188 0.131970-12-021972-02-21 False
+
@@ -625,19 +625,19 @@

Numbers, dates,

- + - + - + @@ -660,15 +660,15 @@

Numbers, dates,
-

143 002,21 1.4March 04 1971February 06 1971 True
201 399,18 201.4February 24 1970April 30 1970 True
100 188,39 0.1December 02 1970February 21 1972 False
+
@@ -781,15 +781,15 @@

Significan
-

+
@@ -867,15 +867,15 @@

Significan
-

+
@@ -955,15 +955,15 @@

Significan
-

+
@@ -1046,15 +1046,15 @@

Replacement

-
+
@@ -1136,15 +1136,15 @@

Replacement

-
+
@@ -1226,15 +1226,15 @@

Replacement

-
+
@@ -1321,15 +1321,15 @@

Replacement

-
+
@@ -1430,15 +1430,15 @@

Escape special c
-

+
@@ -1540,15 +1540,15 @@

Markdown

-
+
@@ -1666,15 +1666,15 @@

Markdown

-
+

Vincent sometimes contributes to these R packages.

@@ -1796,15 +1796,15 @@

Custom functions

-

Vincent sometimes contributes to these R packages.

+
@@ -1923,15 +1923,15 @@

Custom functions

-
+
@@ -2041,15 +2041,15 @@

Quarto data process
-

+
@@ -2129,15 +2129,15 @@

Quarto data process
-

Thing
+
@@ -2220,15 +2220,15 @@

Quarto data process
-

Thing
+
diff --git a/vignettes/group.html b/vignettes/group.html index 5f4e5dc5..d75e461b 100644 --- a/vignettes/group.html +++ b/vignettes/group.html @@ -416,15 +416,15 @@

Rows

-
mpg
+
@@ -617,15 +617,15 @@

Rows

-
+
@@ -765,15 +765,15 @@

Rows

-
+
@@ -912,15 +912,15 @@

Rows

-
+
@@ -1070,15 +1070,15 @@

Rows

-
+
@@ -1288,15 +1288,15 @@

Columns

-
+
@@ -1506,15 +1506,15 @@

Columns

-
Hamburgers
+
@@ -1755,15 +1755,15 @@

Columns

-
Hamburgers
+
diff --git a/vignettes/plot.html b/vignettes/plot.html index b6e801b6..47ef00bc 100644 --- a/vignettes/plot.html +++ b/vignettes/plot.html @@ -427,15 +427,15 @@

Inserting image
-

Hello
+
@@ -520,15 +520,15 @@

Inserting image
-

+
@@ -643,15 +643,15 @@

Built-in plots

-
+
@@ -726,24 +726,24 @@

Built-in plots

- - - - + + + + - - - - + + + + - - - - + + + +
mpg
hp
qsec
@@ -772,15 +772,15 @@

Custom plots: Base
- +
@@ -842,15 +842,15 @@

Custom plots: Base

- + - + - +
mpg
hp
qsec
@@ -883,15 +883,15 @@

Custom plots: g
- +
@@ -953,15 +953,15 @@

Custom plots: g

- + - + - +
mpg
hp
qsec
@@ -1010,15 +1010,15 @@

Custom plots: g
- +
@@ -1092,21 +1092,21 @@

Custom plots: g

- - - + + + - - - + + + - - - + + +
Adelie
Chinstrap
Gentoo
@@ -1128,15 +1128,15 @@

Fontawesome

- +
diff --git a/vignettes/style.html b/vignettes/style.html index a8b8dd77..4698b9b1 100644 --- a/vignettes/style.html +++ b/vignettes/style.html @@ -445,15 +445,15 @@

Cells, rows, columns
-

+
@@ -572,15 +572,15 @@

Cells, rows, columns
-

+
@@ -694,15 +694,15 @@

Cells, rows, columns
-

+
@@ -816,15 +816,15 @@

Cells, rows, columns
-

+
@@ -938,15 +938,15 @@

Cells, rows, columns
-

+
@@ -1060,15 +1060,15 @@

Cells, rows, columns
-

+
@@ -1179,15 +1179,15 @@

Cells, rows, columns
-

+
@@ -1301,15 +1301,15 @@

Cells, rows, columns
-

+
@@ -1425,15 +1425,15 @@

Cells, rows, columns
-

+
@@ -1573,15 +1573,15 @@

Colors

-
+
@@ -1704,15 +1704,15 @@

Alignment

-
+
@@ -1808,15 +1808,15 @@

Alignment

-
+
@@ -1938,15 +1938,15 @@

Alignment

-
+
@@ -2043,15 +2043,15 @@

Font size

-
+
@@ -2176,15 +2176,15 @@

Spanning cell
-

+
@@ -2299,15 +2299,15 @@

Spanning cell
-

+
@@ -2424,15 +2424,15 @@

Spanning cell
-

+
@@ -2554,15 +2554,15 @@

Headers

-
+
@@ -2659,15 +2659,15 @@

Headers

-
+
@@ -2781,15 +2781,15 @@

Headers

-
+
@@ -2912,15 +2912,15 @@

Conditional styling
-

+
@@ -3060,15 +3060,15 @@

Vectorized sty
-

+
@@ -3216,15 +3216,15 @@

Vectorized sty
-

+
@@ -3367,15 +3367,15 @@

Vectorized sty
-

+
@@ -3694,15 +3694,15 @@

Lines (borders)

-
+
@@ -3809,15 +3809,15 @@

Lines (borders)

-
+
@@ -3946,15 +3946,15 @@

Lines (borders)

-
+
@@ -4041,15 +4041,15 @@

Cell padding
-

+
diff --git a/vignettes/theme.html b/vignettes/theme.html index c71b866e..b08ba842 100644 --- a/vignettes/theme.html +++ b/vignettes/theme.html @@ -415,15 +415,15 @@

Visual themes

-
+
@@ -625,15 +625,15 @@

Visual themes

-
+
@@ -938,15 +938,15 @@

Custom themes

-
Always use the same caption.
+
diff --git a/vignettes/tinytable.html b/vignettes/tinytable.html index a8d06c6c..8b5284bb 100644 --- a/vignettes/tinytable.html +++ b/vignettes/tinytable.html @@ -419,15 +419,15 @@

Tiny Tables

-
Always use the same caption.
+
@@ -533,15 +533,15 @@

Width

-
+
@@ -644,15 +644,15 @@

Width

-
+
@@ -756,15 +756,15 @@

Width

-
+
@@ -918,15 +918,15 @@

Width

-
+
@@ -1085,15 +1085,15 @@

Width

-
+
@@ -1175,15 +1175,15 @@

Footnotes

-
+

A full-width table with wrapped text in cells and a footnote.

@@ -1260,15 +1260,15 @@

Footnotes

-

A full-width table with wrapped text in cells and a footnote.

+
@@ -1377,15 +1377,15 @@

Footnotes

-
+
@@ -1510,15 +1510,15 @@

Captions and
-

+
@@ -1655,15 +1655,15 @@

Math

-
+
@@ -1758,15 +1758,15 @@

Line breaks
-

+
@@ -1922,15 +1922,15 @@

Combination an
-

+
@@ -2028,15 +2028,15 @@

Combination an
-

+
@@ -2120,15 +2120,15 @@

Combination an
-

+
@@ -2243,15 +2243,15 @@

Combination an
-

Combine two tiny tables.
+
@@ -2370,15 +2370,15 @@

Combination an
-

Combine two tiny tables.
+
@@ -2489,15 +2489,15 @@

Combination an
-

Combine two tiny tables.
+
diff --git a/vignettes/tinytable_assets/id4aivy0wdixvctic4hycn.png b/vignettes/tinytable_assets/id4aivy0wdixvctic4hycn.png new file mode 100644 index 00000000..e0b2cddc Binary files /dev/null and b/vignettes/tinytable_assets/id4aivy0wdixvctic4hycn.png differ diff --git a/vignettes/tinytable_assets/id4letp39l5lb2aadhlgpy.png b/vignettes/tinytable_assets/id4letp39l5lb2aadhlgpy.png new file mode 100644 index 00000000..8ec24e8d Binary files /dev/null and b/vignettes/tinytable_assets/id4letp39l5lb2aadhlgpy.png differ diff --git a/vignettes/tinytable_assets/id5hgnjgoyaj9qsiij6g6s.png b/vignettes/tinytable_assets/id5hgnjgoyaj9qsiij6g6s.png new file mode 100644 index 00000000..51ac33e1 Binary files /dev/null and b/vignettes/tinytable_assets/id5hgnjgoyaj9qsiij6g6s.png differ diff --git a/vignettes/tinytable_assets/id6czp5936220cbw4pjbf1.png b/vignettes/tinytable_assets/id6czp5936220cbw4pjbf1.png new file mode 100644 index 00000000..fa8a2afc Binary files /dev/null and b/vignettes/tinytable_assets/id6czp5936220cbw4pjbf1.png differ diff --git a/vignettes/tinytable_assets/id6s9kb5nrni5vtakrch87.png b/vignettes/tinytable_assets/id6s9kb5nrni5vtakrch87.png new file mode 100644 index 00000000..b6cc9f62 Binary files /dev/null and b/vignettes/tinytable_assets/id6s9kb5nrni5vtakrch87.png differ diff --git a/vignettes/tinytable_assets/id8meqkd78bufen68ezctb.png b/vignettes/tinytable_assets/id8meqkd78bufen68ezctb.png new file mode 100644 index 00000000..cce55974 Binary files /dev/null and b/vignettes/tinytable_assets/id8meqkd78bufen68ezctb.png differ diff --git a/vignettes/tinytable_assets/id8rewvl4pg1hjbxacbdxa.png b/vignettes/tinytable_assets/id8rewvl4pg1hjbxacbdxa.png new file mode 100644 index 00000000..04b900e8 Binary files /dev/null and b/vignettes/tinytable_assets/id8rewvl4pg1hjbxacbdxa.png differ diff --git a/vignettes/tinytable_assets/id971xmhvfrwvgxldbgwlw.png b/vignettes/tinytable_assets/id971xmhvfrwvgxldbgwlw.png new file mode 100644 index 00000000..0ba387fc Binary files /dev/null and b/vignettes/tinytable_assets/id971xmhvfrwvgxldbgwlw.png differ diff --git a/vignettes/tinytable_assets/id9o7hfkuogbeysw8mc0c0.png b/vignettes/tinytable_assets/id9o7hfkuogbeysw8mc0c0.png new file mode 100644 index 00000000..82861ab5 Binary files /dev/null and b/vignettes/tinytable_assets/id9o7hfkuogbeysw8mc0c0.png differ diff --git a/vignettes/tinytable_assets/idakfg69vnrsusnvir1u4p.png b/vignettes/tinytable_assets/idakfg69vnrsusnvir1u4p.png new file mode 100644 index 00000000..e677d3ef Binary files /dev/null and b/vignettes/tinytable_assets/idakfg69vnrsusnvir1u4p.png differ diff --git a/vignettes/tinytable_assets/idb9gbuegaz245zyu5jidw.png b/vignettes/tinytable_assets/idb9gbuegaz245zyu5jidw.png new file mode 100644 index 00000000..5f1e6473 Binary files /dev/null and b/vignettes/tinytable_assets/idb9gbuegaz245zyu5jidw.png differ diff --git a/vignettes/tinytable_assets/idbnukkyyp6kydg7q2mjdm.png b/vignettes/tinytable_assets/idbnukkyyp6kydg7q2mjdm.png new file mode 100644 index 00000000..d7222e0f Binary files /dev/null and b/vignettes/tinytable_assets/idbnukkyyp6kydg7q2mjdm.png differ diff --git a/vignettes/tinytable_assets/idc3d55j2zxtvkx1tj4svj.png b/vignettes/tinytable_assets/idc3d55j2zxtvkx1tj4svj.png new file mode 100644 index 00000000..80279d32 Binary files /dev/null and b/vignettes/tinytable_assets/idc3d55j2zxtvkx1tj4svj.png differ diff --git a/vignettes/tinytable_assets/idiksvsjxct566upanj1da.png b/vignettes/tinytable_assets/idiksvsjxct566upanj1da.png new file mode 100644 index 00000000..5e33c88b Binary files /dev/null and b/vignettes/tinytable_assets/idiksvsjxct566upanj1da.png differ diff --git a/vignettes/tinytable_assets/idiva3wxvjq9zoo3lpzvsc.png b/vignettes/tinytable_assets/idiva3wxvjq9zoo3lpzvsc.png new file mode 100644 index 00000000..67c9f5e4 Binary files /dev/null and b/vignettes/tinytable_assets/idiva3wxvjq9zoo3lpzvsc.png differ diff --git a/vignettes/tinytable_assets/idkfn6vp65d23pbkzn757y.png b/vignettes/tinytable_assets/idkfn6vp65d23pbkzn757y.png new file mode 100644 index 00000000..1cfe3c01 Binary files /dev/null and b/vignettes/tinytable_assets/idkfn6vp65d23pbkzn757y.png differ diff --git a/vignettes/tinytable_assets/idmc5uhcz69774au09xsnu.png b/vignettes/tinytable_assets/idmc5uhcz69774au09xsnu.png new file mode 100644 index 00000000..213bef86 Binary files /dev/null and b/vignettes/tinytable_assets/idmc5uhcz69774au09xsnu.png differ diff --git a/vignettes/tinytable_assets/idoywiob0k2f9ku1r5pnuc.png b/vignettes/tinytable_assets/idoywiob0k2f9ku1r5pnuc.png new file mode 100644 index 00000000..cba1148d Binary files /dev/null and b/vignettes/tinytable_assets/idoywiob0k2f9ku1r5pnuc.png differ diff --git a/vignettes/tinytable_assets/idpyzkejtagkcme6rik3md.png b/vignettes/tinytable_assets/idpyzkejtagkcme6rik3md.png new file mode 100644 index 00000000..0981e71f Binary files /dev/null and b/vignettes/tinytable_assets/idpyzkejtagkcme6rik3md.png differ diff --git a/vignettes/tinytable_assets/idsz19uly2usveoli1s68z.png b/vignettes/tinytable_assets/idsz19uly2usveoli1s68z.png new file mode 100644 index 00000000..f4e677bc Binary files /dev/null and b/vignettes/tinytable_assets/idsz19uly2usveoli1s68z.png differ diff --git a/vignettes/tinytable_assets/idui154te0tntyvy0w85jw.png b/vignettes/tinytable_assets/idui154te0tntyvy0w85jw.png new file mode 100644 index 00000000..0e9656bb Binary files /dev/null and b/vignettes/tinytable_assets/idui154te0tntyvy0w85jw.png differ diff --git a/vignettes/tinytable_assets/iduxqnjt13o1j90mpx71cc.png b/vignettes/tinytable_assets/iduxqnjt13o1j90mpx71cc.png new file mode 100644 index 00000000..eba06493 Binary files /dev/null and b/vignettes/tinytable_assets/iduxqnjt13o1j90mpx71cc.png differ diff --git a/vignettes/tinytable_assets/idww8l6rejby29on8c6sx8.png b/vignettes/tinytable_assets/idww8l6rejby29on8c6sx8.png new file mode 100644 index 00000000..79d2ec07 Binary files /dev/null and b/vignettes/tinytable_assets/idww8l6rejby29on8c6sx8.png differ diff --git a/vignettes/tinytable_assets/idwz73n6xqhetpjko1zr36.png b/vignettes/tinytable_assets/idwz73n6xqhetpjko1zr36.png new file mode 100644 index 00000000..8eaafeb9 Binary files /dev/null and b/vignettes/tinytable_assets/idwz73n6xqhetpjko1zr36.png differ diff --git a/vignettes/tinytable_assets/idx6b5es9b7mhx6p0tsfdf.png b/vignettes/tinytable_assets/idx6b5es9b7mhx6p0tsfdf.png new file mode 100644 index 00000000..4e1ff0a7 Binary files /dev/null and b/vignettes/tinytable_assets/idx6b5es9b7mhx6p0tsfdf.png differ diff --git a/vignettes/tinytable_assets/idyi6r8zz9vm9ykanuhmbp.png b/vignettes/tinytable_assets/idyi6r8zz9vm9ykanuhmbp.png new file mode 100644 index 00000000..5e2927f9 Binary files /dev/null and b/vignettes/tinytable_assets/idyi6r8zz9vm9ykanuhmbp.png differ diff --git a/vignettes/tinytable_assets/idz35im9r22f84zs07vgg0.png b/vignettes/tinytable_assets/idz35im9r22f84zs07vgg0.png new file mode 100644 index 00000000..3ce82825 Binary files /dev/null and b/vignettes/tinytable_assets/idz35im9r22f84zs07vgg0.png differ diff --git a/vignettes/tinytable_tutorial.pdf b/vignettes/tinytable_tutorial.pdf index 84cbb2a2..37747f2e 100644 Binary files a/vignettes/tinytable_tutorial.pdf and b/vignettes/tinytable_tutorial.pdf differ
Combine two tiny tables.