nice_table.default: Create a nicely formatted table

View source: R/nice_table.R

nice_table.defaultR Documentation

Create a nicely formatted table

Description

This function takes a data frame and formats it into a nicely formatted HTML table using the gt packages.

Usage

## Default S3 method:
nice_table(
  x,
  title = NULL,
  footnote = NULL,
  spanner = NULL,
  row_group = NULL,
  row_group_order = NULL,
  rownames = NULL,
  file = NULL,
  cols_label = NULL,
  decimals = NULL,
  round = NULL,
  label_na = NULL,
  markdown = FALSE,
  gt = NULL,
  sort = NULL,
  sort_decreasing = FALSE,
  ...
)

Arguments

x

The data frame to be formatted into a table

title

Title string.

footnote

Add footnote

spanner

List with information on grouping columns. E.g. spanner = list("M" = 2:3, "SD" = 4:6).

row_group

List with information on grouping rows row_group = list("Start" = 1:2, "That is the second" = 3:5)

row_group_order

List with information on grouping order.

rownames

Logical or NULL. If TRUE, rownames are shown. If NULL, rownames are shown when they are not identical to as.character(1:nrow(x)).

file

Character string with filename. If set, an additional file is exported (html or docx format is possible). If set TRUE, a filename is automatically created based on the title.

cols_label

List with renaming information for columns (old_name = new_name).

decimals

Number of decimals that will be printed.

round

Number of digits to which numbers should be rounded.

label_na

= Label for replacing missing values.

markdown

If TRUE, interprets cell content as markdown.

gt

Additional arguments passed to gt::gt()

...

Various arguments for backward compatibility.

Value

A gt table object.

Examples

df <- data.frame(
  x = 1:5, y = rnorm(5, mean = 10, sd = 12),
  c = letters[5:1], d = sample(letters, 5)
)
nice_table(
  df,
  title = "A nice title",
  footnote = c("Footnote 1", "Footnote 2"),
  spanner = list("One" = 1:2, "Two" = 3:4),
  row_group = list("Start" = 1:2, "That is the second" = 3:5),
  cols_label = list(x = "First", y = "Second", c = "Third", d = "Fourth"),
  decimals = 1
)


jazznbass/wmisc documentation built on Jan. 28, 2025, 11:13 p.m.